我只是難以理解如何處理此代碼,我只是試圖在插入客戶表單上實現「無重複」捕獲,但它只是通過我的if語句每次都去別的地方。這是來源。我也嘗試了.Equals具有相同的結果:(將數據源中的值與字符串進行比較
Protected Sub srcAllClients_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles srcAllClients.Inserting
'Establish Variables
Dim emailAddress As String
Dim srcUsers As SqlDataSource = New SqlDataSource()
srcUsers.ConnectionString = ConfigurationManager.ConnectionStrings("ISSD21ConnectionString").ConnectionString
Dim view As DataView
view = DirectCast(srcUsers.Select(DataSourceSelectArguments.Empty), DataView)
srcUsers.SelectCommand = "SELECT EmailAddress FROM ISSDClients"
srcUsers.DataSourceMode = SqlDataSourceMode.DataReader
Dim reader As IDataReader
reader = DirectCast(srcUsers.Select(DataSourceSelectArguments.Empty), IDataReader)
emailAddress = FormView1.FindControl("txtEmail").ToString
While reader.Read()
If reader("EmailAddress") = (emailAddress) Then
lblError.Text = "Your Email is NOT Unique!"
'this is where we cancel the update and return an error
Else
lblError.Text = "Your Email is Unique!"
'nothing needs to happen, maybe just tell them that it went through
End If
End While
reader.Close()
End Sub
好點!我錯過了這個在我原來閃閃發光的... – Achilles 2010-06-24 18:18:57
Thx的小費,就在這筆錢。只是你給我的代碼... 錯誤1'TextBox'是一種類型,不能用作表達式。 \t 錯誤2')'預計。 – javArc 2010-06-24 18:23:04
啊,對不起,我的VB很生鏽。鑄造是不同的 - 代碼應該是emailAddress = CType(FormView1.FindControl(「txtEmail」),TextBox).Text – womp 2010-06-24 18:25:26