主题:vb.net2005中的UPDATE问题
数据库是ACCESS,用VB.NET2005去写,想用UPDATE更新数据库,运行一直弹出问题,提示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