Sunday, March 11, 2012

Adding Records to SQL DB

Here's my dilema. I'm using VB.Net 2003 and SQL DB

I'm having a problen adding a record to a table in my SQL DB

My previous experience has been working with Access databases.

When I try to create an SQLDataAdapter using the wizard from the toolbox the wizard will only create the Select statement. it won't create the UPDATE, DELETE or INSERT statements. I'm not sure why, I even tried using the form wizard and it still wouldn't work...

My tables all have primary keys defined.

So I decided that I would try to create everything programatically.

What I need to know is how to create the INSERT statement and which statements to use to add the record to the table.

I know that when using the OLEDataAdapter with the Acces DB I would do something like the following code.


MyNewRow = MyDatSet.Tables("MyTable").NewRow

MyDataSet.Tables("MyTable").Rows.Add(MyNewRow)
MyDataAdapter.Update(MyDataSet, "MyTable")

I'm pretty sure that for an SQL DB it is different but I don't know how to do it.

Can anyone please help ?

I should also mention that all my textbox fields on my form are databound..

thanks

tattoo

If you define no command on the dataadapter, then no command will be executed. Have a look at the commandbuilder. It will create commands for the apropiate DELETE / INSERT / UPDATE statements based on the underlying schema. If you don′t want to use the (auto)generated command, you can also assign these commands manully. But if you do not give the dataadater any information on how to proceed on the DML action, no action will be done during the udate.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment