|
I use vb.net connection to update the Access database. The data types of textbox4 and textbox5 are both numbers, and the others are text. When adding records, as long as the data type added is correct, you can continue to add records, but once the data type added is wrong, an error warning pops up even if the data type of the records added later is correct, why is this so? Which expert can help my little brother? Thanks in advance! Here is my code: 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) in the above formula stands for single quote, because the ASCII code for single quote is 39. So Chr (39) can also be replaced with "'", because the format of the INSERT statement is: INSERT INTO table name (field 1, field 2, field 3 ...) VALUES (' value 1 ',' value 2 ',' value 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 ("Wrong type! Please verify!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub |
|