|
我用vb.net连接更新Access数据库,其中textbox4跟textbox5的数据类型都为数字,而其他的都为文本。在添加记录时,只要添加的数据类型没错,那就可以继续添加记录,但一旦添加的数据类型出错,以后添加的记录的数据类型尽管没错也会弹出出错警告,为什么会这样啊?哪位高手能帮帮小弟吗?在此先谢谢了!下面是我的代码: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQL As String
Dim addItem As OleDb.OleDbCommand
Try
SQL = "INSERT INTO message VALUES(" + Chr(39) + CStr(TextBox5.Text) + Chr(39) + "," + Chr(39) + CStr(TextBox1.Text) + Chr(39) + "," + Chr(39) + CStr(TextBox2.Text) + Chr(39) + "," + Chr(39) + CStr(TextBox3.Text) + Chr(39) + "," + Chr(39) + CStr(TextBox4.Text) + Chr(39) + ")"
'上式中的Chr(39)代表单引号,因为单引号的ASCII码是39。所以Chr(39)也可以用"'"代替,因为INSERT语句格式为:INSERT INTO 表名(字段1,字段2,字段3……) VALUES('值1','值2','值3'……)
OleDbConnection1.Open()
addItem = New OleDb.OleDbCommand(SQL, OleDbConnection1)
addItem.ExecuteNonQuery()
OleDbConnection1.Close()
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11, "message")
xianshi()
Catch ex As Exception
MessageBox.Show("类型不对!请核实!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub |
|