Я столкнулся с проблемой при вставке данных в файл mdb
Я получаю синтаксическую ошибку в инструкции INSERT INTO , и причина скрыта для меня, я отладил все это с прошлого четверга, и до сих пор нет веской причины, почему я получаю эту ошибку
Am facing a problem while inserting data to mdb file Public Class SuppliersManagement Dim cnnOLEDB As New OleDbConnection Dim cmdOLEDB As New OleDbCommand Dim cmdInsert As New OleDbCommand Dim cmdUpdate As New OleDbCommand Dim cmdDelete As New OleDbCommand Dim SystemUserName As String = Environment.UserName Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\SupplierDB.mdb" Private Sub Fill_Suppliers_Data() Try Dim sqlQRY As String sqlQRY = "Select * From Supp_Users" Dim da As OleDbDataAdapter Dim ds As DataSet = New DataSet da = New OleDbDataAdapter(sqlQRY, cnnOLEDB) Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da) da.Fill(ds, "Supp_Users") DataGridSupplierMGT.DataSource = ds DataGridSupplierMGT.DataMember = "Supp_Users" lbl_RowCount.Text = DataGridSupplierMGT.RowCount Dim row As Integer If DataGridSupplierMGT.RowCount > 0 Then DataGridSupplierMGT.Columns("Supp_UserName").ReadOnly = True DataGridSupplierMGT.Columns("EmailTo").Visible = False DataGridSupplierMGT.Columns("EmailCC").Visible = False DataGridSupplierMGT.Columns("Password").Visible = False DataGridSupplierMGT.Columns("Supp_Domain").Visible = False DataGridSupplierMGT.Columns("ID").Visible = False row = DataGridSupplierMGT.FirstDisplayedCell.RowIndex DataGridSupplierMGT.Rows(row).Selected = True If RowIndex_TXT.Text = vbNullString Then Exit Sub Else Me.DataGridSupplierMGT.ClearSelection() Me.DataGridSupplierMGT.Rows(RowIndex_TXT.Text).Selected = True Me.DataGridSupplierMGT.FirstDisplayedScrollingRowIndex = RowIndex_TXT.Text End If Else row = 0 End If Catch ex As OleDbException MessageBox.Show(ex.Message) End Try End Sub Private Sub AddNew_BTN_Click(sender As Object, e As EventArgs) Handles AddNew_BTN.Click Try If RecordID_TXT.Text = "" Then If MessageBox.Show("Do you want to Add a New Record?", "Insert", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then Exit Sub Else If SuppNameVariable.Text <> "" And Supp_domain_TXT.Text <> "" And Supp_Pass_TXT.Text <> "" And MailAdress_Holder_TXT_TO.Text <> "" And MailAdress_Holder_TXT_CC.Text <> "" Then If cnnOLEDB.State = ConnectionState.Open Then cnnOLEDB.Close() End If cnnOLEDB.Open() cmdInsert.CommandText = "INSERT INTO Supp_Users (Supp_UserName, Supp_Domain, Password, EmailTo, EmailCC) VALUES ('" & SuppNameVariable.Text & "', '" & Supp_domain_TXT.Text & "', '" & Supp_Pass_TXT.Text & "', '" & MailAdress_Holder_TXT_TO.Text & "', '" & MailAdress_Holder_TXT_CC.Text & "');" cmdInsert.CommandType = CommandType.Text cmdInsert.Connection = cnnOLEDB cmdInsert.ExecuteNonQuery() MsgBox("Record added successfully.") RecordID_TXT.Text = "" SuppNameVariable.Text = "" Supp_domain_TXT.Text = "" Supp_Pass_TXT.Text = "" MailAdress_Holder_TXT_TO.Text = "" MailAdress_Holder_TXT_CC.Text = "" lbl_RowCount.Text = DataGridSupplierMGT.RowCount Else MsgBox("Please make sure to add below data:" & vbNewLine & "1. Supplier Name" & vbNewLine & "2. Supplier Domain" & vbNewLine & "3. Supplier Password" & vbNewLine & "4. Email To" & vbNewLine & "5. Email CC") lbl_RowCount.Text = DataGridSupplierMGT.RowCount End If End If End If lbl_RowCount.Text = DataGridSupplierMGT.RowCount cmdInsert.Dispose() Fill_Suppliers_Data() If DataGridSupplierMGT.RowCount > 0 Then DataGridSupplierMGT.ClearSelection() Me.DataGridSupplierMGT.FirstDisplayedScrollingRowIndex = Me.DataGridSupplierMGT.RowCount - 1 Me.DataGridSupplierMGT.Rows(Me.DataGridSupplierMGT.RowCount - 1).Selected = True End If Catch ex As OleDbException MessageBox.Show(ex.Message) End Try End Sub
Что я уже пробовал:
Am facing a problem while inserting data to mdb file Public Class SuppliersManagement Dim cnnOLEDB As New OleDbConnection Dim cmdOLEDB As New OleDbCommand Dim cmdInsert As New OleDbCommand Dim cmdUpdate As New OleDbCommand Dim cmdDelete As New OleDbCommand Dim SystemUserName As String = Environment.UserName Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\SupplierDB.mdb" Private Sub Fill_Suppliers_Data() Try Dim sqlQRY As String sqlQRY = "Select * From Supp_Users" Dim da As OleDbDataAdapter Dim ds As DataSet = New DataSet da = New OleDbDataAdapter(sqlQRY, cnnOLEDB) Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da) da.Fill(ds, "Supp_Users") DataGridSupplierMGT.DataSource = ds DataGridSupplierMGT.DataMember = "Supp_Users" lbl_RowCount.Text = DataGridSupplierMGT.RowCount Dim row As Integer If DataGridSupplierMGT.RowCount > 0 Then DataGridSupplierMGT.Columns("Supp_UserName").ReadOnly = True DataGridSupplierMGT.Columns("EmailTo").Visible = False DataGridSupplierMGT.Columns("EmailCC").Visible = False DataGridSupplierMGT.Columns("Password").Visible = False DataGridSupplierMGT.Columns("Supp_Domain").Visible = False DataGridSupplierMGT.Columns("ID").Visible = False row = DataGridSupplierMGT.FirstDisplayedCell.RowIndex DataGridSupplierMGT.Rows(row).Selected = True If RowIndex_TXT.Text = vbNullString Then Exit Sub Else Me.DataGridSupplierMGT.ClearSelection() Me.DataGridSupplierMGT.Rows(RowIndex_TXT.Text).Selected = True Me.DataGridSupplierMGT.FirstDisplayedScrollingRowIndex = RowIndex_TXT.Text End If Else row = 0 End If Catch ex As OleDbException MessageBox.Show(ex.Message) End Try End Sub Private Sub AddNew_BTN_Click(sender As Object, e As EventArgs) Handles AddNew_BTN.Click Try If RecordID_TXT.Text = "" Then If MessageBox.Show("Do you want to Add a New Record?", "Insert", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then Exit Sub Else If SuppNameVariable.Text <> "" And Supp_domain_TXT.Text <> "" And Supp_Pass_TXT.Text <> "" And MailAdress_Holder_TXT_TO.Text <> "" And MailAdress_Holder_TXT_CC.Text <> "" Then If cnnOLEDB.State = ConnectionState.Open Then cnnOLEDB.Close() End If cnnOLEDB.Open() cmdInsert.CommandText = "INSERT INTO Supp_Users (Supp_UserName, Supp_Domain, Password, EmailTo, EmailCC) VALUES ('" & SuppNameVariable.Text & "', '" & Supp_domain_TXT.Text & "', '" & Supp_Pass_TXT.Text & "', '" & MailAdress_Holder_TXT_TO.Text & "', '" & MailAdress_Holder_TXT_CC.Text & "');" cmdInsert.CommandType = CommandType.Text cmdInsert.Connection = cnnOLEDB cmdInsert.ExecuteNonQuery() MsgBox("Record added successfully.") RecordID_TXT.Text = "" SuppNameVariable.Text = "" Supp_domain_TXT.Text = "" Supp_Pass_TXT.Text = "" MailAdress_Holder_TXT_TO.Text = "" MailAdress_Holder_TXT_CC.Text = "" lbl_RowCount.Text = DataGridSupplierMGT.RowCount Else MsgBox("Please make sure to add below data:" & vbNewLine & "1. Supplier Name" & vbNewLine & "2. Supplier Domain" & vbNewLine & "3. Supplier Password" & vbNewLine & "4. Email To" & vbNewLine & "5. Email CC") lbl_RowCount.Text = DataGridSupplierMGT.RowCount End If End If End If lbl_RowCount.Text = DataGridSupplierMGT.RowCount cmdInsert.Dispose() Fill_Suppliers_Data() If DataGridSupplierMGT.RowCount > 0 Then DataGridSupplierMGT.ClearSelection() Me.DataGridSupplierMGT.FirstDisplayedScrollingRowIndex = Me.DataGridSupplierMGT.RowCount - 1 Me.DataGridSupplierMGT.Rows(Me.DataGridSupplierMGT.RowCount - 1).Selected = True End If Catch ex As OleDbException MessageBox.Show(ex.Message) End Try End Sub