When I run my project it keeps on giving me errors. The first exception is at da.Fill(dt). It says that IErrorInfo.GetDescription Failed With E_FAIL(0x80004005). The second exception is at cmd.ExecuteNonQuery() and says syntax error in INSERT INTO statement. Please help me. I'm quite new to VB so I couldn't really see the problem even if I looked at it all day.
Public Class Telephone_Bill
Dim cnn As New OleDb.OleDbConnection
Private Sub RefreshData()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT Month as [Month], " & _
"Day as [Day], Year, Amount Paid, Amount Due, Mode of Payment, Company Name " & _
" FROM Transactions ORDER BY Month", cnn)
Dim dt As New DataTable
Transaction_Log.dgvTransaction.DataSource = dt
da.Fill(dt)
cnn.Close()
End Sub
Private Sub btnProceed_Click(sender As System.Object, e As System.EventArgs) Handles btnProceed.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
cmd.CommandText = "INSERT INTO Transactions([Month], [Day], [Year], AmountPaid, AmountDue, ModeofPayment, CompanyName) " & _
" VALUES(" & cboMonth1.SelectedItem & ",'" & cboDay1.SelectedItem & "','" & _
cboYear1.SelectedItem & "','" & txtAmount.Text & "','" & _
txtTotalCharges.Text & "','" & cboMonetary.SelectedItem & "','" & _
txtCompName.Text & "')"
cmd.ExecuteNonQuery()
RefreshData()
cnn.Close()
End Sub
Private Sub Telephone_Bill_Load(sender As Object, e As System.EventArgs) Handles Me.Load
cnn = New OleDb.OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Accounts for Bill Payment Center.accdb"
Me.RefreshData()
End Sub
End Class