i am writing a code where the user will update the staff,but my update command has some problems. i think its the comma's in my command,can somebody help me.......

this is my code

Imports System.Data.OleDb
Public Class EditDeleteStaff

    Dim PwdCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "/Blindz.mdb; Jet OLEDB:Database Password=;" 'Persist Security Info=False;" if your DB is not PWD protected
    Dim oledbcon As New OleDbConnection(PwdCon)
    Dim dsID As New DataSet()
    Dim daID As New OleDbDataAdapter()
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.Hide()
        Manager.Show()
    End Sub

    Private Sub EditDeleteStaff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim PwdCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "/Blindz.mdb; Jet OLEDB:Database Password=;"
        Dim oledbcon As New OleDbConnection(PwdCon)
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim jobstat As String = ""
        Dim num1, num2, num3, num4, num5, num6 As Boolean
        Dim phone, icnum, genId As String
        Dim i As Integer = 0
        num1 = IsNumeric(telbox.Text)
        num2 = IsNumeric(telbox2.Text)
        num3 = IsNumeric(IcNumbox.Text)
        num4 = IsNumeric(IcNumbox2.Text)
        num5 = IsNumeric(IcNumbox3.Text)
        num6 = IsChar(namebox.Text)
        If Ftime.Checked = True Then
            jobstat = Ftime.Text
        End If
        If Ptime.Checked = True Then
            jobstat = Ptime.Text
        End If

        'THIS ALL CHANGE TO UPDATEEEE!!!!!


        If namebox.Text = "" OrElse _
            addbox.Text = "" OrElse _
            telbox2.Text = "" OrElse _
             telbox.Text = "" OrElse _
             syspass.Text = "" OrElse _
             IcNumbox.Text = "" OrElse _
             IcNumbox2.Text = "" OrElse _
             IcNumbox3.Text = "" OrElse _
             posbox.Text = "" OrElse _
             jobstat = "" Then
            MessageBox.Show("All feilds must be filled")

        ElseIf num1 = False Or num2 = False Or num3 = False Or num4 = False Or num5 = False Then
            MessageBox.Show("Ic number and telephone number cannot have characters")
        ElseIf num6 = False Then
            MessageBox.Show("Name Cannot Contain Numbers")
        ElseIf telbox.TextLength < 2 Or telbox2.TextLength < 7 Then
            MessageBox.Show("Not a Valid telephone Number")
        ElseIf IcNumbox.TextLength < 6 Or IcNumbox2.TextLength < 2 Or IcNumbox3.TextLength < 4 Then
            MessageBox.Show("Not a Valid Malaysian Ic Number")
        Else
            phone = telbox.Text + "-" + telbox2.Text
            icnum = IcNumbox.Text + "-" + IcNumbox2.Text + "-" + IcNumbox3.Text
            Try
                oledbcon.Open()
                Dim strSQL As String = ("UPDATE Staff SET StaffName = [" & namebox.Text & "] ,Address = [" & addbox.Text & "] ,Phone = [" & phone & "] ,JobPosition = [" & posbox.Text & "] ,JobStat = [" & genId & "]  WHERE {SID=" & id.Text & "}")
                Dim cmd As OleDbCommand = New OleDbCommand(strSQL, oledbcon)
                Dim objread As OleDbDataReader
                objread = cmd.ExecuteReader

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                oledbcon.Close()
            End Try
End If 
End Sub

Enclose text field values in quotes:

Dim strSQL As String = ("UPDATE Staff SET StaffName = ['" & _
  namebox.Text & "'] ,Address = ['" & addbox.Text & _
  "'] ,Phone = ['" & phone & "'] ,JobPosition = ['" & _
  posbox.Text & "'] ,JobStat = ['" & genId & _
  "']  WHERE SID='" & id.Text & "'")

If SID field is numeric, remove quotes from it.

You need to change a command to cmd.ExecuteNonQuery

I would build a dataAdapter for this instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.