所以每当我Click
注册Button
时,浏览器都会向我显示此错误:
"语法错误:'@live'运算符后缺少操作数。"
和堆栈跟踪:
> [SyntaxErrorException: Syntax error: Missing operand after '@live' operator.]
System.Data.ExpressionParser.Parse() +2082709
System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +131
System.Data.DataTable.Select(String filterExpression) +107
Class1.Authenticate(String id, String pas) +196
Class1.add(String Email, String pas, String Name, DateTime SignDate) +205
SignUp.Button1_Click(Object sender, EventArgs e) +148
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9692746
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562
这是我网站的班级代码:
Public Class Class1
Private Shared dsPubs As DataSet
Public dr As DataRow
Public Function Authenticate(ByVal id As String, ByVal pas As String) As Integer
Dim strConnectionString As String = "Integrated Security=SSPI;Initial Catalog=Shop;Data Source=."
Dim instsqlconnection As SqlConnection = New SqlConnection(strConnectionString)
instsqlconnection.Open()
Dim daCstmrs As New SqlDataAdapter("Select * From Customer_Detail", instsqlconnection)
dsPubs = New DataSet("Customer")
daCstmrs.Fill(dsPubs, "login")
instsqlconnection.Close()
Dim drResult As DataRow() = dsPubs.Tables("login").Select(" EmailAddress = " + id.ToString())
If (drResult.Length > 0) Then
If drResult(0)("Password").ToString().Trim() = pas Then
Return 1
Else
Return 2
End If
Else
Return 0
End If
End Function
Public Function add(ByVal Email As String, ByVal pas As String, ByVal Name As String, ByVal SignDate As Date) As Integer
Dim strConnectionString As String
Dim instsqlconnection As SqlConnection
strConnectionString = "Integrated Security=SSPI;Initial Catalog=Shop;Data Source=."
instsqlconnection = New SqlConnection(strConnectionString)
instsqlconnection.Open()
Dim daCstmrs As New SqlDataAdapter("Select * From Customer_Detail", instsqlconnection)
Dim dsPubs As New DataSet("Customer")
Dim table As DataTable = New DataTable("login")
daCstmrs.Fill(dsPubs, "login")
instsqlconnection.Close()
Dim a As Integer = Authenticate(Email, pas)
If (a = 0) Then
Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(daCstmrs)
Dim dr As DataRow
dr = dsPubs.Tables("login").NewRow()
dr("EmailAddress") = Email
dr("Password") = pas
dr("Name") = Name
dr("DateOBirth") = SignDate
dsPubs.Tables("login").Rows.Add(dr)
daCstmrs.Update(dsPubs, "login")
Return 1
Else
Return 2
End If
End Function
最后,这是注册button
OnClick
代码:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim p As New Class1
Dim y As Integer
y = p.add(Me.EmailSignUp.Text, Me.PassSignUp.Text, Me.NameSignUp.Text, Me.DobSignUp.Text)
If (y = 1) Then
Response.Redirect("CheckOut.aspx")
Else
Me.Label6.Text = "add failed "
End If
End Sub
我不知道我应该怎么做才能避免在浏览器上出现错误并成功将记录添加到数据库中。我知道'@'
有一些东西应该修复,但不知道是什么。
经过多次尝试缩小我的问题所在,我发现我的问题来自这一行:
Dim drResult As DataRow() = dsPubs.Tables("login").Select(" EmailAddress = " + id.ToString())
与id.ToString相关的东西,它只有在我输入一个数字时才有效,否则它一直向我显示错误!
正如@Andrew Morton所说,在id字符串周围添加单引号将解决问题!
Dim drResult As DataRow() = dsPubs.Tables("login").选择(" 电子邮件地址 = " + id.ToString())
将成为 :
将 drResult 调暗为 DataRow() = dsPubs.Tables("login").选择("EmailAddress = '" & id & "'")