Guys i am writing program, in which i have to insert data then update the data and then delete it,
now i am able to insert the data, but when i try to update i just retrive the data but when i try to change it , it gives me error, "Syntax error in update statement
Please help me if you can. thanks
Below is the code in which i got problem.
now i am able to insert the data, but when i try to update i just retrive the data but when i try to change it , it gives me error, "Syntax error in update statement
Please help me if you can. thanks
Below is the code in which i got problem.
Imports System.Data
Imports System.Data.OleDb
Public Class DocChange
Dim cnnOLEDB As New OleDbConnection
Dim con As New OleDb.OleDbConnection
Dim cn As OleDb.OleDbConnection
Dim cmd As OleDbCommand
Dim da As New OleDbDataAdapter
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim str As String
Dim cmdDelete As New OleDbCommand
'Dim con As New OleDbConnection
Dim dr As OleDbDataReader
Dim sql As String
Dim sql2 As String
'Dim cmd As OleDbCommand
Dim date1 As String
Dim date2 As String
Dim result As Integer
Dim sql3 As String
Dim sql4 As String
'Dim cn As OleDb.OleDbConnection
Dim strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS\MOMS\WindowsApplication2\MOMS.accdb"""
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
DocAdd.Show()
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
Me.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
DocDelete.Show()
Me.Hide()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnquiry.Click
DocEnquiry.Show()
Me.Hide()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click
Main_Menu.Show()
Me.Hide()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Application.Exit()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListing.Click
DocListing.Show()
Me.Hide()
End Sub
Private Sub DocChange_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim connectionStr As String
connectionStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS\MOMS\WindowsApplication2\MOMS.accdb"
sql = "Select * FROM Doctor WHERE DoctorID = @DoctorID"
Dim cn As OleDbConnection = New OleDbConnection(connectionStr)
cn.Open()
cmd = New OleDbCommand(sql, cn)
cmd.Parameters.AddWithValue("DoctorID", txtdoctorid.Text)
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
While (dr.Read())
txtSurname.Text = dr.Item("Surname").ToString
txtTitle.Text = dr.Item("Title").ToString
txtAddress.Text = dr.Item("Address").ToString
txtCityTown.Text = dr.Item("City Town").ToString
txtState.Text = dr.Item("State").ToString
txtZip.Text = dr.Item("zip").ToString
txtRegNo.Text = dr.Item("RegNo").ToString
txtPhoneNo.Text = dr.Item("Phone No").ToString
txtMobileNo.Text = dr.Item("Mobile No").ToString
txtUnitCode.Text = dr.Item("Unit Code").ToString
txtCategory.Text = dr.Item("Category").ToString
End While
cn.Close()
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim con As OleDbConnection
Dim sql As String
str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS 3\MOMS2\WindowsApplication2\MOMS.accdb"
con = New OleDbConnection(str)
'sql = "Update * FROM Doctor WHERE DoctorID = @DoctorID"
'sql = "update students set name=" & sname.Text & ",mobile=" & mobile.Text & ",email=" & email.Text & " where roll=" & roll.Text & ""
' sql = "UPDATE Doctor SET [Doc-ID]='" & txtdocid.Text & ",[Doc-Surname]=" & txtdocsur.Text & ",[DocTitle]=" & txtdoctitle.Text & ",[DocAddress]=" & txtdocadd.Text & ",[DocCityTown]=" & txtdoccity.Text & ",[DocState]=" & txtdocstate.Text & ",[Doczip]=" & txtdoczip.Text & ",[DocRegNo]=" & txtdocreg.Text & ",[DocPhone1]=" & txtdocphone.Text & ",[DocHandphone]=" & txtdocmobile.Text & ",[DocUnitCode]=" & txtdocunit.Text & ",[DocCategory]=" & txtdoccat.Text & ""
'sql = "UPDATE Doctor SET [Doc-ID] = @txtdocid , [Doc-Surname] = @txtdocsur , [DocTitle] = @txtdoctitle , [DocAddress] = @txtdocadd , [DocCityTown] = @txtdoccity , [DocState] = @txtdocstate , [Doczip] = @txtdoczip , [DocRegNo] = @txtdocreg , [DocPhone1] = @txtdocphone , [DocHandphone] = @txtdocmobile , [DocUnitCode] = @txtdocunit , [DocCategory] = @txtdoccat "
sql = "UPDATE Doctor SET ([Doctor ID],[Surname],[Title],[Address],[City Town],[State],[Zip],[RegNo],[Phone No],[Mobile No],[Unit Code],[Category])values('" & txtdoctorid.Text & "', '" & txtSurname.Text & "', '" & txtTitle.Text & "', '" & txtAddress.Text & "', '" & txtCityTown.Text & "', '" & txtState.Text & "', '" & txtZip.Text & "', '" & txtRegNo.Text & "', '" & txtPhoneNo.Text & "', '" & txtMobileNo.Text & "', '" & txtUnitCode.Text & "', '" & txtCategory.Text & "')"
Dim cmd As OleDbCommand
Try
con.Open()
cmd = New OleDbCommand(sql, con)
cmd.ExecuteScalar()
MessageBox.Show("Update Successfully")
con.Close()
cmd.Dispose()
Catch ex As OleDbException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
Private Sub txtSurname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSurname.TextChanged
End Sub
End Class