我只是难以理解如何处理此代码,我只是试图在插入客户表单上实现“无重复”捕获,但它只是通过我的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