第 1 行: '=' 附近有语法错误。

[复制链接]
查看11 | 回复1 | 2010-6-19 16:42:01 | 显示全部楼层 |阅读模式
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。
源错误:
行 44:
Dim adp As New SqlDataAdapter(cmd)
行 45:
Dim ds As New DataSet
行 46:
adp.Fill(ds, "Customer") '填充dataset
行 47:
DataGrid1.DataSource = ds.Tables("Customer").DefaultView'指定数据源
行 48:
'ds.Tables("Customer").DefaultView.Sort = sortfield '指定排序字段
源文件: D:\CusInfo_34zpc\zuhechaxun.aspx.vb
行: 46
堆栈跟踪:
[SqlException: 第 1 行: '=' 附近有语法错误。]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +45
System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +5
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
CusInfo_34zpc.zuhechaxun.binddata() in D:\CusInfo_34zpc\zuhechaxun.aspx.vb:46
CusInfo_34zpc.zuhechaxun.Button3_Click(Object sender, EventArgs e) in D:\CusInfo_34zpc\zuhechaxun.aspx.vb:119
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
谢谢我看半天···
Sub binddata()

Dim conn As New SqlConnection("server=(local);database=CusMgt_34zpc;uid=sa;pwd=")'建立connection对象

Dim strSql As String

strSql = "select * from Customer" & Session("fieldstring") & " order by CustomerID"

Dim cmd As New SqlCommand(strSql, conn)

Dim adp As New SqlDataAdapter(cmd)

Dim ds As New DataSet

adp.Fill(ds, "Customer")

DataGrid1.DataSource = ds.Tables("Customer").DefaultView

DataGrid1.DataBind()

End Sub

Private Sub chaxun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chaxun.Click

If Not Session("fieldstring") = "" Then

Session("fieldstring") &= "where" & Session("fieldstring")

End If

binddata()

End Sub
这分别是其中binddata的和查询部分代码

回复

使用道具 举报

千问 | 2010-6-19 16:42:01 | 显示全部楼层
把你的sql语句贴出来。"SELECT * FROM Customer" & Session("fieldstring") & " ORDER BY CustomerID"从这句还是看不出一的问题所在,Session("fieldstring")大概是些WHERE方面的子句。不过如果你这些部分都没问题,我认为问题出在你Customer后面没有空格上。你先如下修改试试。"SELECT * FROM Customer " & Session("fieldstring") & " ORDER BY CustomerID"如果还是不行,就必须设置断点调试一下看看Session("fieldstring")里面是什么东西。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行