Question error in INSERT INTO

Haseo

Member
Joined
Jul 16, 2012
Messages
16
Programming Experience
Beginner
{System.Data.OleDb.OleDbException}<<<<<<<< ERROR



CONNECTION CODE


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnn = New OleDb.OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\ReservationData.mdb"
Me.RefreshData()
' DataGridView1.Hide()
End Sub
Private Sub RefreshData()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT infoID as [Booking No], " & _
"checkcon as [Check if Confirm], DateB as [Date Booked], Occasion, DateE as [Date of Events], Time, Place, Cperson as [Contact Person], Phone as [Tell/Cell No], Package, Quote " & _
"FROM reserv ORDER BY infoID", cnn)
Dim dt As New DataTable


da.Fill(dt)


Me.DataGridView1.DataSource = dt


cnn.Close()
End Sub




add CODE....

Private Sub btnaddnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddnew.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn


If Me.txtinfoID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO reserv(infoID, checkcon, DateB, Occasion, DateE, Time, Place, Cperson, Phone, Package, Quote) " & _
" VALUES(" & Me.txtinfoID.Text & "','" & Me.txtcheckcon.Text & "','" & _
Me.dtpdatebooked.Text & "','" & Me.cbboccasion.Text & "','" & _
Me.dtpdateevent.Text & "','" & Me.txttime.Text & "','" & _
Me.txtplace.Text & "','" & Me.txtcperson.Text & "','" & _
Me.txttell.Text & "','" & Me.txtpackage.Text & "','" & _
Me.txtquote.Text & "')"


cmd.ExecuteNonQuery() <<<< ERROR {System.Data.OleDb.OleDbException}


Else


cmd.CommandText = "UPDATE reserv " & _
" SET infoID=" & Me.txtinfoID.Text & _
" checkcon=" & Me.txtcheckcon.Text & "'" & _
" DateB=" & Me.dtpdatebooked.Text & "'" & _
" Occasion=" & Me.cbboccasion.Text & "'" & _
" DateE=" & Me.dtpdateevent.Text & "'" & _
" Time=" & Me.txttime.Text & "'" & _
" Place=" & Me.txtplace.Text & "'" & _
" Cperson=" & Me.txtcperson.Text & "'" & _
" Phone=" & Me.txttell.Text & "'" & _
" Package=" & Me.txtpackage.Text & "'" & _
" Quote=" & Me.txtquote.Text & "'" & _
" WHERE ID=" & Me.txtinfoID.Tag


cmd.ExecuteNonQuery()


End If


RefreshData()


Me.btnclear.PerformClick()


cnn.Close()


End Sub
 
"INSERT INTO reserv(infoID, checkcon, DateB, Occasion, DateE, Time, Place, Cperson, Phone, Package, Quote) "

As you are addressing the database directly shouldn't these be the actual table column names rather than your aliases?
 
yes that's my actual table column and i try to run it and it's working with the datagridview but when i try to add there's some error with my code... i double check my table column and it's the same with my code..
 
Also what is the reserv for?

its my table name..... ^_^ here's the actual error... see the picture...... i try to create a database again but its the same error....
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    112.6 KB · Views: 43
Don't use string concatenation to insert values into SQL code. Always use parameters. To learn why and how, follow the Blog link in my signature and check out my post on Parameters In ADO.NET.
 
thanks for the help....

i found out that there's a missing character on my code..... thanks for your help

There's lots of missing characters, i.e. single quotes. You don't have to use single quotes at all when do it properly, i.e. use parameters, so you can't make that mistake.
 

Similar threads

Back
Top