What is wrong with this?
da.InsertCommand = New OleDb.OleDbCommand("Insert Into Table1 Values( 1, '" & TextBox1.Text & "')")
da.InsertCommand.Connection = con
con.Open()
da.Update(ds)
con.Close()
The database is never updated no matter what.
Or is there a better way to insert into db? I have tried the CommandBuilder but it doesnt seem to work as well.
Or can I directly execute a query on my database in VB.NET?
You are a bit confused regarding on what DataAdapter.Update does.
The Update works applying your InsertCommand, UpdateCommand, DeleteCommand to every Added, Modified or Deleted rows present in your DataSource (supposing ds is a DataSet).
It doesn’t add/delete/update a record to the database by itself.
If you want to add a record to the database you should write (pseudo)code like this
Note the use of the Using statement to be sure of closing and disposing the connection and the command. Also, never concatenate strings to build sql commands. Using parameters avoid parsing problems and SQLInjection attacks.
EDIT: Based on your comment below and supposing that the first column of the Table1 is an autonumber field you could change the code in this way
Also, for the problem for ‘nothing has been added’ I think you have the database file (mdb) included in your project and the property
Copy To The Output Directoryset toCopy AlwaysSee a detailed explanation on MSDN at this page