Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TableAdapater Update With Joined Tables 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I'm confused and missing something very basic here. I use SQL stored procs to fill my dataset and they usually contain joins for purposes of displaying descriptions, names, etc. Up until now I have really only updated, inserted, deleted records one at a time and have a stored proc for each type of action. I would like to use the TableAdapater update method to save the changes for an entire table with one command. I don't want or need to update any of the joined tables that are only providing the descriptions or names. I have also read numerous posts on the internet that say you have to write your own methods when you have a join in your select of the Fill for the TableAdapater. I'm just not sure how to do this and how to call the code with the proper parameters. I'm not using any of the visual designers in .Net to create my stored procedures or database connections. Can someone point me in the right direction or possibly supply a simple example.


Auguy
Sylvania/Toledo Ohio
 

to change the SQL of a TableAdapter's command objects:

tableadapter.InsertCommand.CommandText = "INSERT INTO SQLDbase..." (or DeleteCommand, SelectCommand, UpdateCommand)

You can make the SQL with parameters, like this:

Insert Into <tablename> (Field1, Field2) Values (@Field1, @Field2)

then add the parameters to the InsertCommand:

tableadapter.InsertCommand.Parameters.Add("@Field1", SqlDbType.VarChar, 8, "Field1") 'look up the SQLCommand's Parameter object to see what these constrictor parameters do

tableadapter.InsertCommand.Parameters.Add("@Field2", SqlDbType.VarChar, 8, "Field1") 'note that the parameters need to be added to the command object in the same order they appear in the SQL

tableadapter.Update(<tablename>) 'this runs all updates, inserts, deletes since last Update


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks, just what I was looking for. Really don't know why I struggled so much with this.

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top