插入命令不插入数据库?
你好,
有人可以告诉我这段代码中做错了什么吗
Protected Sub insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Insert.Click
Dim mydb As New OleDbConnection
mydb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |datadirectory|database.mdb;Persist Security Info=True")
mydb.Open()
Dim sqlstring = "INSERT INTO [maintable] ([field1], [field2]) VALUES (@textbox1, @textbox2);"
Dim mydbcommand As New OleDbCommand(sqlstring, mydb)
TextBox1.Text = mydbcommand.Parameters.Add("@textbox1", OleDbType.VarChar).Value
TextBox2.Text = mydbcommand.Parameters.Add("@textbox2", OleDbType.VarChar).Value
mydbcommand.ExecuteNonQuery()
mydb.Close()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
HI
could someone tell me what i am doing wrong in this code
Protected Sub insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Insert.Click
Dim mydb As New OleDbConnection
mydb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |datadirectory|database.mdb;Persist Security Info=True")
mydb.Open()
Dim sqlstring = "INSERT INTO [maintable] ([field1], [field2]) VALUES (@textbox1, @textbox2);"
Dim mydbcommand As New OleDbCommand(sqlstring, mydb)
TextBox1.Text = mydbcommand.Parameters.Add("@textbox1", OleDbType.VarChar).Value
TextBox2.Text = mydbcommand.Parameters.Add("@textbox2", OleDbType.VarChar).Value
mydbcommand.ExecuteNonQuery()
mydb.Close()
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该使用
而不是
尝试它并告诉我你是否仍然面临问题
i think you should use
instead of
try it and tell me if you still face the problem