nkim mink

nkim mink

  • NA
  • 5
  • 2k

Syntax error in string in query expression '','','','','','','')'.

Jul 16 2012 1:22 AM
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        Dim cmd As New OleDb.OleDbCommand
        If Not con.State = ConnectionState.Open Then
            'open connection if not open
            con.Open()
        End If
        cmd.Connection = con
        'check whether add new or update
        If Me.txthireeid.Tag & "" = "" Then
            'add data to table
            'add data to table 



            cmd.CommandText = " INSERT INTO hiree(HireeID,First_Name,Second_Name,Organisation_Name,Mobile_No,Workphone_No,Address)" & _
                              " VALUES(" & Me.txthireeid.Text & "','" & Me.txtfirstname.Text & "','" & _
                              Me.txtsecondname.Text & "','" & Me.txtorgname.Text & "','" & _
                              Me.txtmobileno.Text & "','" & Me.txtworkphoneno.Text & "','" & Me.txtaddress.Text & "')"
            cmd.ExecuteNonQuery()
        Else
            cmd.CommandText = "UPDATE Hiree" & _
            " SET HireeID=" & Me.txthireeid.Text & _
            ", First_Name=" & Me.txtfirstname.Text & "'" & _
            ", Second_Name=" & Me.txtsecondname.Text & "'" & _
            ", Organisation_Name=" & Me.txtorgname.Text & "'" & _
            ",Mobile_No=" & Me.txtmobileno.Text & "'" & _
            ",Workphone_No=" & Me.txtworkphoneno.Text & _
            ",Address=" & Me.txtaddress.Text & _
            "WHERE HireeID=" & Me.txthireeid.Tag
            cmd.ExecuteNonQuery()
        End If
        'refresh data in list
        refreshdata() 
        Me.btnclear.PerformClick()
        'close connection
        con.Close()
    End Sub
    Private Sub refreshdata()
        Dim cmd As New OleDb.OleDbCommand
        If Not con.State = ConnectionState.Open Then
            'open connection if not open
            con.Open()
        End If
        Dim da As New OleDb.OleDbDataAdapter("SELECT HireeID as [ID]," & _
                                             "First_Name as [Name],Second_Name,Organisation_Name,Mobile_No,Workphone_No,Address" & _
                                             " FROM Hiree ORDER BY HireeID", con)

        Dim dt As New DataTable
        da.Fill(dt)
        Me.dgvhireedetails.DataSource = dt
        con.Close()






    End Sub

Answers (4)