SQLAdapter - Insert problem

D

Dave

I using a SQLAdapter and Dataset to retrieve and update
rows in a single table ... but I do not know how to
Insert a new row. The table's key column is a auto
generated field so it is read only (and therefore I
cannot make changes to it). How do I specify to the
SQLAdapter that I want an Insert vs. an update?

I haven't tried to delete rows ... but I expect I will
have the same problem.

Any help on this is appreciated.
Thanks!
Dave
 
S

Stephen Muecke

Dave,
Did you create you DataAdapter by dragging a table onto your form or
component? If so, the Insert, Update and Delete commands will have been
automatically created for you. Calling the Update method of the DataAdapter
will check the state of the rows (New, Modified or Deleted) and perform the
required inserts, updates and deletions.
You can also set the commands in code
myDataAdaptor.InsertCommand.CommandTest = "INSERT ........"
Stephen
 
D

Dave

Stephen,
Yes, I dragged a SQLDataAdapter onto the form and added a
Dataset. I can see the generated Insert and Delete code,
but when I try to add a row it updates the last row
accessed in my dataset. I have a single form that I am
trying to simply update/add/delete rows. The key column
is a SQL identity (auto-number) and it remains in the
dataset after I clear all of the other columns ... which
I suppose is my problem. Is there a way to clear the
entire row before I populate the new row? And if so, do
I leave the key/identity column null or blank? Sure do
appreciate your help thanks!
Dave
 
M

Martin Liedtke

Hi Dave,
did you set this key-column
to AutoIncrement = True ?
So if you add a new row this column will be
autoincremented.
then the insert statement knows that this is a auto number!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top