Getting a error that I haven't been able to figure out. Goggled it with no luck hope someone can help.
Adding a contact to the access mdb database and checking the Contact_Id if the user exists.
Syntax error in INSERT INTO statement
Imports System.Data
Imports System.Data.OleDb
Public Class Modify
Private _contactID As Int32 = 0
Public Property Contact_ID() As Int32
Get
Return _contactID
End Get
Set(ByVal value As Int32)
_contactID = value
End Set
End Property
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim conn As New OleDbConnection _
("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" _
& Application.StartupPath & "\Contacts.mdb")
Dim sql As String = String.Empty
If _contactID = 0 Then
sql = "INSERT INTO Contacts (First Name, Last Name, Address, Phone Number, Email Address, Cell Phone) VALUES ('" & tbFName.Text & "','" & tbLName.Text & "','" & tbAddress.Text & "','" & tbPhoneNum.Text & "','" & tbEmail.Text & "','" & tbCellNum.Text & "')"
End If
'Opens the database and then opens the sql command
conn.Open()
'sets command as new instance of OleDbCommand and then runs ExecuteNonQuery
'Closes connection
Dim command As New OleDbCommand(sql, conn)
command.ExecuteNonQuery()
conn.Close()
'Closes the forum
Me.Close()
End Sub
End Class
Comments