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
VulpesPosted Jul 16, 2012, 9:32 AM
String literals should, of course, have a single quote character added at either end.
VulpesPosted Jul 19, 2012, 10:04 AM
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 & "')"
and this for the UPDATE command :
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 & "'"
nkim minkPosted Jul 19, 2012, 3:14 AM
nkim minkPosted Jul 19, 2012, 3:07 AM