跪求大家解决值行SQL语句出错!
我值行SQL语句时后出现如下错误请问是什么问题!
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在system.data.dll 中。
我的程序代码如下:
Dim strCon As String = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = hjlotus.mdb "
Dim myconn As New OleDb.OleDbConnection(strCon)
myConn.Open()
Dim strInsert As String = "INSERT INTO ckb ( rkhh , rkrq , rkxx, rkxm , rkjs) VALUES ( ' " & _rkhh.Text + " ' , ' " & _rkrq.Value + " ' , ' " & _rkxx.Text + " ' , ' " & rkxm.Text + " ' , ' " & _rkjs.Text + " ') "
Dim myCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand(strInsert, myconn)
myCommand.ExecuteNonQuery()
myConn.Close()
请大家指点一下为什么会出现上面那个错误!
[解决办法]
或者你把+换成 &
[解决办法]
sql语句错误,可能输入框数据和数据字段定义不一致,或者输入框中包含单引号“ '”
Dim strInsert As String = "INSERT INTO ckb ( rkhh , rkrq , rkxx, rkxm , rkjs) VALUES ( ' " & _rkhh.Text & " ', ' " & _rkrq.Value & " ' , ' " & _rkxx.Text & " ' , ' " & rkxm.Text & " ' , ' " & _rkjs.Text & " ') "
[解决办法]
我知道用datagridview DATAGRID没用过 呵呵~~
Dim Dt As New DataSet
Dim DBReader As New OleDb.OleDbDataAdapter
Try
OleComm = New OleDb.OleDbCommand
With OleComm
.CommandText = OLeCommStr
.Connection = OledbS 'OleDbConnection
End With
DBReader.SelectCommand = OleComm 'SQL select 语句
Dt.Clear()
DBReader.Fill(Dt, "DB ")
DGV1.DataSource = Dt.Tables( "DB ") 'datagridview控件
Catch ex As Exception
MsgBox( "处理数据时发生错误3: " & ex.Message.ToString)
End Try
[解决办法]
把楼上的后段改成
DataGrid.DataSource = ds.Tables(0)
[解决办法]
换成 &
Dim Dt As New DataSet
Dim DBReader As New OleDb.OleDbDataAdapter
Try
OleComm = New OleDb.OleDbCommand
With OleComm
.CommandText = OLeCommStr
.Connection = OledbS 'OleDbConnection
End With
DBReader.SelectCommand = OleComm 'SQL select 语句
Dt.Clear()
DBReader.Fill(Dt, "DB ")
DGV1.DataSource = Dt.Tables( "DB ") 'datagridview控件
Catch ex As Exception
MsgBox( "处理数据时发生错误3: " & ex.Message.ToString)
End Try