SQLAdapter - Insert problem

  • Thread starter Thread starter Dave
  • Start date Start date
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
 
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
 
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
 
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!
 
Back
Top