我是新來的。我有個問題。重新加載頁面再次運行我的事件處理程序
Everywhere是可以的,但是當我點擊F5時,它會刷新頁面並再次運行代碼。這意味着在每個F5上的數據庫中都會添加一條新記錄。
這是我的代碼,你有什麼建議嗎?
Imports System.Data.OleDb
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim myConn As OleDbConnection
Dim cmd As OleDbCommand
Dim sqlstring, Fname, Lname, FATHname, Region As String
Fname = TextBox1.Text
Lname = TextBox2.Text
FATHname = TextBox3.Text
Region = TextBox4.Text
myConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\pcuser10.comm\Documents\vwd.data.accdb")
myConn.Open()
sqlstring = " INSERT INTO Table1 (FNAME, LNAME, FATHNAME, REGION) VALUES ('" + Fname + "','" + Lname + "','" + FATHname + "','" + Region + "')"
cmd = New OleDbCommand(sqlstring, myConn)
cmd.ExecuteNonQuery()
myConn.Close()
End Sub
End Class
由於您是新手,請探索現有問題。這個已經回答了,例如http://stackoverflow.com/q/1558790/532498甚至更好看這裏http://stackoverflow.com/questions/1135404/btnadd-click-fires-when-i-press-f5 – Pleun
謝謝你的幫助,我使用Response.Redirect(Request.RawUrl,true),它刷新頁面並清除字段,解決了我的問題,再次感謝你 – user1000744