Question update problem

Sundip Mistry

New member
Joined
Dec 12, 2011
Messages
2
Programming Experience
Beginner
Hi there,

i've written all my code up to send or create data in access however I keep receiving the error of :-

OleDbException was unhandled
Syntax error in INSERT INTO statement.

I haven't got the faintest clue of what's gone wrong, I'm a beginner hear, just started programming a few weeks or a month ago.

If someone can help me, I'd be really grateful.

thank You and much appreciation
Sundip

Following syntax (vb.net)

Imports System.Data.OleDb
Private Sub showItems()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter


con.Open()
da = New OleDbDataAdapter("Select * from MainT", con)
da.Fill(dt)
con.Close()


End Sub

Private Sub frm_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'connection between vb.net & microsoft access
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data source=C:\Users\Sundip\Documents\Visual Studio 2010\Projects\WareHouse_Stock_Auto_Controller\WareHouse_Stock_Auto_Controller\stock.mdb"
con.Open()
con.Close()


showItems()
End Sub

Private Sub bttn_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttn_Add.Click
Dim Iteming As String


Iteming = txt_Add.Text
lst_Items.Items.Add(txt_Add.Text)


con.Open()


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


da = New OleDbDataAdapter("Select * from MainT", con)
da.Fill(dt)


Dim newRow As DataRow = dt.NewRow
With newRow
.Item("ID") = txt_ID.Text
.Item("ProductName") = txt_Add.Text
End With


dt.Rows.Add(newRow)


Dim cb As New OleDbCommandBuilder(da)
da.Update(dt)
con.Close()


showItems()


End Sub
 
Probably one of your columns in your MainT table is named using a reserved word, like Password

Attach a copy of your db (empty of data if confidentiality is a concern) and we'll have a look
 
ps, you seem to be following a really old tutorial for your coding. Read the DW4 link in my signature for the modern, official microsft way to do your data access. Start with the Creating a Simple Data App tutorial.. You'll probably also find it doesnt suffer the problem your current code is having
 
Probably one of your columns in your MainT table is named using a reserved word, like Password

Attach a copy of your db (empty of data if confidentiality is a concern) and we'll have a look
Thank you cjard, This was the problem, I can't thank you enough, thanks again! It is much appreciated.
 
Back
Top