rdcustomer = cmcustomer.ExecuteReader(CommandBehavior.CloseConnection)总提示我这句 不对!~为什么 请高手指教

解决方案 »

  1.   

    第 1 行: '=' 附近有语法错误。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误: 
    行 54:         cnNorthWind.Open()
    行 55:         Dim rdcustomer As SqlDataReader
    行 56:         rdcustomer = cmcustomer.ExecuteReader(CommandBehavior.CloseConnection)
    行 57:         If rdcustomer.Read Then
    行 58:             txCustomerID.Text = rdcustomer.GetString(0)
     源文件: E:\www\WebApplication3\WebForm1.aspx.vb    行: 56 堆栈跟踪: 
    [SqlException: 第 1 行: '=' 附近有语法错误。]
       System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
       System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
       WebApplication3.WebForm1.bnsearch_Click(Object sender, EventArgs e) in E:\www\WebApplication3\WebForm1.aspx.vb:56
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain() 
    --------------------------------------------------------------------------------
      

  2.   

    scommandText = "select customerID,companyname,contactname,phone,fax from customers"
    --->
    scommandText = "select customerID,companyname,contactname,phone,fax from customers  "
    最后加个空格试试
      

  3.   

    scommandText = scommandText & "where customerID=" & txparameter.Text
    如果customerID是int, 不需要单引号
      

  4.   

    scommandText = scommandText & "where comanyname like '" & txparameter.Text & "'"
    ---》
    scommandText = scommandText & "where comanyname like '%" & txparameter.Text & "%'"