Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Syntax Error In INSERT INTO Statement

$
0
0
Hello guys.
So I'm creating a membership system for my project in school.
My problem is when I'm going to add a new member and save it, this error occurs and it says,
"OleDbException was Unhandled, Syntax Error in INSERT into statement"

Here's the code of the form:
Public Class frmAddMember

    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Me.Hide()
        frmMembers.Show()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        con.Open()

        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDb.OleDbDataAdapter

        da = New OleDb.OleDbDataAdapter("SELECT * FROM [tblAddMember]", con)
        da.Fill(dt)

        Dim newRow As DataRow = dt.NewRow

        ' If txtFirstName.text = txtLastName.text Then
        With newRow
            .Item("FirstName") = txtFirstName.Text
            .Item("MiddleName") = txtMidName.Text
            .Item("LastName") = txtLastName.Text
            .Item("ContactNumber") = txtContactNum.Text
            .Item("E-mailAddress") = txtEmailAdd.Text
            .Item("DateRegistered") = txtDateReg.Text
            .Item("ExpirationOfAccount") = txtExpired.Text
            .Item("AccountUsername") = txtAccountUser.Text
            .Item("Archive") = "No"
        End With
        ' Else

        '   End If

        dt.Rows.Add(newRow)
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        da.Update(dt) //this is where the error is//
        con.Close()

        MsgBox("Saved Successfully!", MsgBoxStyle.Information)
        Me.Close()
        frmMembers.Show()
    End Sub

    Private Sub txtFirstName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirstName.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtFirstName.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtFirstName.Focus()
                Exit Sub
            End If
            txtMidName.Focus()
        End If
    End Sub

    Private Sub txtMidName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMidName.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtMidName.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtLastName.Focus()
                Exit Sub
            End If
            txtMidName.Focus()
        End If
    End Sub

    Private Sub txtLastName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLastName.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtLastName.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtLastName.Focus()
                Exit Sub
            End If
            txtContactNum.Focus()
        End If
    End Sub

    Private Sub txtContactNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtContactNum.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtContactNum.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtContactNum.Focus()
                Exit Sub
            End If
            txtEmailAdd.Focus()
        End If
    End Sub

    Private Sub txtEmailAdd_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEmailAdd.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtEmailAdd.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtEmailAdd.Focus()
                Exit Sub
            End If
            txtDateReg.Focus()
        End If
    End Sub

    Private Sub txtDateReg_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDateReg.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtDateReg.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtDateReg.Focus()
                Exit Sub
            End If
            txtExpired.Focus()
        End If
    End Sub

    Private Sub txtExpired_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtExpired.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtExpired.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtExpired.Focus()
                Exit Sub
            End If
            txtAccountUser.Focus()
        End If
    End Sub

    Private Sub txtAccountUser_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAccountUser.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If txtAccountUser.Text.Trim = "" Then
                MsgBox("Fill up the required fields.", MsgBoxStyle.Exclamation, "Insert Query")
                txtAccountUser.Focus()
                Exit Sub
            End If
            btnSave.Focus()
        End If
    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        txtDateReg.Text = Me.DateTimePicker1.Text
    End Sub

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
        txtExpired.Text = Me.DateTimePicker2.Text
    End Sub
End Class



Your help would be appreciated. Thanks.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>