Imports System.Data.OleDb
Public Class Form1
#Region "Declaration"
Dim Conn As OleDbConnection
Dim Comm As OleDbCommand
Dim OleA As OleDbDataAdapter
Dim DSSearch As New DataSet
Dim DS As New DataSet
Dim DsA
Dim SQL As String
Dim Drow As DataRow
#End Region
Private Sub MyConnect()
Try
Conn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=ICON.mdb")
Conn.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisClearTxt()
ShowGrid()
End Sub
Private Sub DisClearTxt()
TxtStNo.Clear()
TxtAddress.Clear()
TxtLName.Clear()
TxtFName.Enabled = False
TxtMName.Enabled = True
TxtAddress.Enabled = False
TxtLandLineNo.Enabled = False
TxtCellNo.Enabled = False
TxtEmail.Enabled = False
TxtCellNo.Enabled = False
TxtNationality.Enabled = False
TxtBday.Enabled = False
CbxGender.Enabled = False
CbxStatus.Enabled = False
End Sub
Private Sub EnableTxt()
TxtFName.Enabled = True
TxtMName.Enabled = True
TxtLName.Enabled = True
TxtAddress.Enabled = True
TxtLandLineNo.Enabled = True
TxtCellNo.Enabled = True
TxtEmail.Enabled = True
TxtCellNo.Enabled = True
TxtNationality.Enabled = True
TxtBday.Enabled = True
CbxGender.Enabled = True
CbxStatus.Enabled = True
TxtStNo.Focus()
End Sub
Private Sub ShowGrid()
MyConnect()
SQL = "Select * From tblMembers"
Comm = New OleDbCommand(SQL, Conn)
OleA = New OleDbDataAdapter(Comm)
DS.Clear()
OleA.Fill(DS, "tblMembers")
Dgvshow.DataSource = DS
Dgvshow.DataMember = "tblMembers"
Conn.Close()
End Sub
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
If BtnAdd.Text = "&Add" Then
BtnAdd.Text = "&Save"
EnableTxt()
Else
MyConnect()
SQL = "INSERT INTO tblMembers(StNo,FName,LName,MName,Address,LandLineNo,CellNo,Email,Gender,Nationality,Bday,Status) Values ('" & TxtStNo.Text & "', '" & TxtFName.Text & "','" & TxtMName.Text & "','" & TxtLName.Text & "','" & TxtAddress.Text & "'," & TxtLandLineNo.Text & "," & TxtCellNo.Text & ",'" & TxtEmail.Text & "'," & CbxGender.Text & ",'" & TxtNationality.Text & "'," & TxtBday.Text & ",'" & CbxStatus.Text & "')"
Comm = New OleDbCommand(SQL, Conn)
Comm.ExecuteNonQuery()
MsgBox("Record saved!")
ShowGrid()
Conn.Close()
BtnAdd.Text = "&Add"
DisClearTxt()
End If
End Sub
Private Function SearchRecord() As Boolean
Dim StrStNo As String = InputBox("Input Student Number", "Record Search")
MyConnect()
SQL = "Select StNo,FName,MName,LName,Address,LandLineNo,CellNo,Email,Gender,Status,Bday,Nationality FROM tblMEmbers WHERE StNo = '" & StrStNo & "'"
Comm = New OleDbCommand(SQL, Conn)
OleA = New OleDbDataAdapter(Comm)
DSSearch.Clear()
OleA.Fill(DSSearch, "tblMembers")
If DSSearch.Tables(0).Rows.Count > 0 Then
Drow = DSSearch.Tables("tblMembers").Rows(0)
TxtStNo.Text = Drow("StNo")
TxtFName.Text = Drow("FName")
TxtMName.Text = Drow("MName")
TxtLName.Text = Drow("LName")
TxtAddress.Text = Drow("Address")
TxtLandLineNo.Text = Drow("LandLineNo")
TxtCellNo.Text = Drow("CellNo")
TxtNationality.Text = Drow("Nationality")
TxtBday.Text = Drow("Bday")
CbxGender.Text = ("Gender")
CbxStatus.Text = ("Status")
SearchRecord = True
Else
SearchRecord = False
End If
End Function
Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
If BtnEdit.Text = "&Edit" Then
If SearchRecord() Then
BtnEdit.Text = "&Update"
EnableTxt()
Else
MsgBox("Record does not exist! duh?")
End If
Else
MyConnect()
SQL = "Update tblsMembers SET StNo ='" & TxtStNo.Text & "',FName ='" & TxtFName.Text & "',MName = '" & TxtLName.Text & "',Gender = '" & CbxGender.Text & "',Status = '" & CbxStatus.Text & "', Address = '" & TxtAddress.Text & "',LandLineNo =" & TxtLandLineNo.Text & ", CellNo =" & TxtCellNo.Text & ",Bday = " & TxtBday.Text & ",Nationality ='" & TxtNationality.Text & "',Email='" & TxtEmail.Text & "'"
Comm = New OleDbCommand(SQL, Conn)
Comm.ExecuteNonQuery()
MsgBox("Record Updated!")
BtnEdit.Text = "&Edit"
DisClearTxt()
Conn.Close()
ShowGrid()
End If
End Sub
Private Sub BtnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
If SearchRecord() Then
If MsgBox("Delete This Record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
MyConnect()
SQL = "Delete FROM tblMembers Where Stno = '" & TxtStNo.Text & "'"
Comm = New OleDbCommand(SQL, Conn)
Comm.ExecuteNonQuery()
MsgBox("Record Deleted!")
Conn.Close()
ShowGrid()
DisClearTxt()
End If
End If
End Sub
Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click
Me.Close()
End Sub
End Class
so, this is my codes
The error occurs when I execute the program and this part will be affected:
Comm.ExecuteNonQuery()and it says that "SYNTAX ERROR INSERT INTO STATEMENT"
what should i do here?
I am stuck help me please?
thanks..

New Topic/Question
Reply




MultiQuote





|