ติดโค๊ด update ค่ะ VB2005 error syntax error in update statement ค่ะรบกวนด้วยนะค่ะ
Tags: Windows, VB, .NET 3.0, VS 2005, Access
Code (VB.NET)
ImportsSystem.Data
ImportsSystem.Data.OleDb
PublicClass Change
Dim myConn As OleDbConnection
Dim sql As String
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim da1 As OleDbDataAdapter
Dim myCmd As OleDb.OleDbCommand
Private Sub FrmCommand_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\PharmacySystem.mdb;")
myConn.Open()
End Sub
Private Sub BT3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT3.Click
Dim sqlem As String
Dim currentem As String
Dim dr As DataRow
Dim pk(1) As DataColumn
Dim Isfind As Boolean = False
If TextBox1.Text = "" Then Exit Sub
sqlem = "SELECT Em_ID ,First_Name FROM Employees"
da = New OleDbDataAdapter(sqlem, myConn)
da.Fill(ds, "Employees")
Try
ListBox1.Items.Clear()
pk(0) = ds.Tables("Employees").Columns("Em_ID")
ds.Tables("Employees").PrimaryKey = pk
dr = ds.Tables("Employees").Rows.Find(TextBox1.Text)
If dr IsNot Nothing Then
currentem = CStr(dr(0)) & " " & CStr(dr(1))
ListBox1.Items.Add(currentem)
Else
ListBox1.Items.Add("ไม่มีชื่อที่ต้องการ")
End If
Catch ex As Exception
MsgBox("NO DATA")
End Try
Dim com As New OleDbCommand
With com
.CommandText = "[serchem]"
.CommandType = CommandType.StoredProcedure
.Connection = myConn
da1 = New OleDbDataAdapter(com)
da1.SelectCommand.Parameters.Add("@Em_ID", OleDbType.LongVarChar).Value = TextBox1.Text
If Isfind = True Then
ds.Tables("Employees").Clear()
End If
da1.Fill(ds, "Employees")
If ds.Tables("Employees").Rows.Count <> 0 Then
Isfind = True
TextBox1.Focus()
End If
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As String
Dim b As String
Dim c As Integer
a = CStr(TextBox1.Text)
b = CStr(TextBox2.Text)
c = CInt(TextBox3.Text)
myCmd = New OleDbCommand(" UPDATE Employees SET User = '" & b & "',Password = '" & c & "'" & _
" WHERE Em_ID = " & a, myConn)
Try
myCmd.ExecuteNonQuery()
MessageBox.Show("แก้ไขข้อมูลเรียบร้อยแล้ว", "ผลการทำงาน", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ErrFromInsert As Exception
MessageBox.Show("ไม่สามารถแก้ไขข้อมูลใหม่ได้กรุณาตรวจสอบชื่อลูกค้า! "& _
ErrFromInsert.Message, "ข้อผิดพลาด", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
EndClass
***หนูดูตรง out put มันขึ้นว่า A first chance exception of type ' System.Data.OleDb.OleDbException' occurred in System.Data.dll
รบกวนด้วยน๊ะคัะ ขอบคุนทุกท่านค่ะ
Tag : .NET, Ms Access, MySQL, VBScript, VB.NET, VS 2005 (.NET 2.x)