主题:用VB.NET2005中的UPDATE的问题
数据库是ACCESS,用VB.NET2005更新数据库,但总是报错,提示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
请大家帮帮忙,谢谢
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
请大家帮帮忙,谢谢