'我的这段代码的意思就是:表table1里面的id的字段的类型是数字类型int,我要按照id来查询,id的值是个变量,我就这样写.
Dim str As Integer
dbname = Server.MapPath("IS.mdb")
myconnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
adp.SelectCommand = com
myconnection.Open()
com.Connection = myconnection
com.CommandText = "select * from table1 where id='" + str + "'" '这样写不行
com.CommandText = "select * from table1 where id='" + CInt(str) + "'" '这样写也不行
ds.Clear()
adp.Fill(ds, "tb")
DataGrid1.DataSource = ds.Tables("tb").DefaultView
DataGrid1.DataBind()
'他提示如下:
'异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配或者输入的字符串格式不匹配
'源错误:
'行(86) : com.CommandText = "select * from table1 where id='" + str + "'"
'行(87) : ds.Clear()
' 行(88) : adp.Fill(ds, "tb")
' 行(89) : DataGrid1.DataSource = ds.Tables("tb").DefaultView
' 行(90)