Hello

I'm totally lost in ADO.NET ! I'm very experienced with VB6 + VB.NET
along with ADO. But now im trying to develop code for ADO.NET using
VB.NET working with Access 2007 database.

My simplest goal is to add a row to my table. It's giving me a
headache. This is my code:


Dim conString As String = "PROVIDER=Microsoft.Ace.OLEDB.12.0;Persist
Security Info=False; Data Source=C:\DB.Accdb"
Dim con As OleDbConnection = New OleDbConnection(conString)

con.Open()

Dim dAdapter = New OleDbDataAdapter("SELECT * FROM [Files]", con)
Dim dSet As New DataSet
dAdapter.Fill(dSet)

Dim dTable As DataTable = dSet.Tables(0)

Dim cb As New OleDb.OleDbCommandBuilder(dAdapter)

Dim dRow As DataRow = dTable.NewRow()
dRow("FilePath") = "C:\MyFile.txt"
dRow("Size") = "1024"
dTable.Rows.Add(dRow)

dAdapter.Update(dSet.GetChanges)
dSet.AcceptChanges()

con.Close()


---
The above code gives me error "Syntax error in INSERT INTO statement."
I tried to check the commandbuilder's commandtext property, it showed
me this:
"INSERT INTO Files (FilePath, Size) VALUES (?, ?)"

I cant believe how complex microsoft made this thing ! Earlier it was
so easy to obtain a recordset and add rows and then call the update.
Now I have to declare so many objects and call so many methods but
still no success.

Some guy told me to use manual sql statements in
dAdapter.InsertCommand instead of commandbuilder. My question is ...
WHY!!? If im using manual statement to update my database, why did I
even have to create a new row, assign data to it and add it to table.
I couldve run a simple INSERT sql to add my data to database.

What is wrong with me code ? Why is it not working. I don't want to
use manual sql for adding my rows to database.. i mean whats to point
of ADO.NET anyway if manual is the right solution.

To unsubscribe from this group, send email to 
dotnetdevelopment+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to