主题:求助,VB.NET2005中UPDATE的问题
数据库是ACCESS,想用UPDATE更新数据库,代码如下:
Imports System.Data.OleDb
Public Class frmedituser
Dim myconnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1.mdb")
Dim mycommand As OleDbCommand
Dim myreader As OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Trim(TextBox2.Text) = "" Then
MsgBox("输入的用户姓名不能为空", MsgBoxStyle.Information, "提示")
Exit Sub
ElseIf Trim(TextBox3.Text) = "" Then
MsgBox("输入的用户密码不能为空", MsgBoxStyle.Information, "提示")
Exit Sub
End If
myconnection.Open()
Dim sqlstring As String = "update systemusers set name ='" & TextBox2.Text & "',password ='" & TextBox3.Text & "',position ='" & TextBox4.Text & "',phone ='" & TextBox5.Text & "',E-MAIL ='" & TextBox6.Text & "' where userid = '" & listbox1.SelectedItem & "'"
mycommand = New OleDbCommand(sqlstring, myconnection)
Try
mycommand.ExecuteNonQuery()
Catch c As Exception
MsgBox(c.ToString)
End Try
myconnection.Close()
mycommand.Dispose()
End Sub
但总是弹出窗口说UPADATE语法错误,我不知道哪里错了,请高手告知
Imports System.Data.OleDb
Public Class frmedituser
Dim myconnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1.mdb")
Dim mycommand As OleDbCommand
Dim myreader As OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Trim(TextBox2.Text) = "" Then
MsgBox("输入的用户姓名不能为空", MsgBoxStyle.Information, "提示")
Exit Sub
ElseIf Trim(TextBox3.Text) = "" Then
MsgBox("输入的用户密码不能为空", MsgBoxStyle.Information, "提示")
Exit Sub
End If
myconnection.Open()
Dim sqlstring As String = "update systemusers set name ='" & TextBox2.Text & "',password ='" & TextBox3.Text & "',position ='" & TextBox4.Text & "',phone ='" & TextBox5.Text & "',E-MAIL ='" & TextBox6.Text & "' where userid = '" & listbox1.SelectedItem & "'"
mycommand = New OleDbCommand(sqlstring, myconnection)
Try
mycommand.ExecuteNonQuery()
Catch c As Exception
MsgBox(c.ToString)
End Try
myconnection.Close()
mycommand.Dispose()
End Sub
但总是弹出窗口说UPADATE语法错误,我不知道哪里错了,请高手告知