主题:VB.net数据库操作中遇到的问题
OleDbConnection1.Open()
Dim name As New OleDbParameter("@ name", OleDbType.Char, 10)
Dim sex As New OleDbParameter("@ sex", OleDbType.Char, 2)
Dim NO As New OleDbParameter("@ NO", OleDbType.Integer, 10)
Dim age As New OleDbParameter("@ age", OleDbType.Integer, 10)
Dim zhuanye As New OleDbParameter("@ zhuanye", OleDbType.Char, 10)
Dim strin As String = "Insert into table1(姓名,学号,性别,年龄,专业) Values(@ name,@ NO,@ sex,@ age,@ zhuanye)"
Dim objcom As New OleDbCommand(strin, OleDbConnection1)
objcom.Parameters.Add(name)
objcom.Parameters.Add(NO)
objcom.Parameters.Add(sex)
objcom.Parameters.Add(age)
objcom.Parameters.Add(zhuanye)
name.Value = textbox1.Text
NO.Value = TextBox2.Text
sex.Value = TextBox3.Text
age.Value = TextBox4.Text
zhuanye.Value = TextBox5.Text
[color=FF0000] objcom.ExecuteNonQuery()[/color]
OleDbConnection1.Close()
Dim strsql = "Select * from table1"
OleDbDataAdapter1.SelectCommand = New OleDbCommand(strsql, OleDbConnection1)
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11, "table1")
这段代码我看了很久也想了很久,但是老是objcom.ExecuteNonQuery()报出异常数据库的连接可以保证没错。请高手指点一下
Dim name As New OleDbParameter("@ name", OleDbType.Char, 10)
Dim sex As New OleDbParameter("@ sex", OleDbType.Char, 2)
Dim NO As New OleDbParameter("@ NO", OleDbType.Integer, 10)
Dim age As New OleDbParameter("@ age", OleDbType.Integer, 10)
Dim zhuanye As New OleDbParameter("@ zhuanye", OleDbType.Char, 10)
Dim strin As String = "Insert into table1(姓名,学号,性别,年龄,专业) Values(@ name,@ NO,@ sex,@ age,@ zhuanye)"
Dim objcom As New OleDbCommand(strin, OleDbConnection1)
objcom.Parameters.Add(name)
objcom.Parameters.Add(NO)
objcom.Parameters.Add(sex)
objcom.Parameters.Add(age)
objcom.Parameters.Add(zhuanye)
name.Value = textbox1.Text
NO.Value = TextBox2.Text
sex.Value = TextBox3.Text
age.Value = TextBox4.Text
zhuanye.Value = TextBox5.Text
[color=FF0000] objcom.ExecuteNonQuery()[/color]
OleDbConnection1.Close()
Dim strsql = "Select * from table1"
OleDbDataAdapter1.SelectCommand = New OleDbCommand(strsql, OleDbConnection1)
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11, "table1")
这段代码我看了很久也想了很久,但是老是objcom.ExecuteNonQuery()报出异常数据库的连接可以保证没错。请高手指点一下