Update several tables with one dataset update

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

How can I update several tables (with possible same field names) from one
dataset with one data adapter. How to implement it with one dataadapter. I
have about 300 tables to update from the current dataset and I do not want
to open 300 data adapters...
Advice

Cheers,
Tamir Khason
 
One approach would be to reuse the DataAdapter and create a For Each
Datatable in your DataSet loop. Create the appropriate Command and related
Command properties per each DataTable."Tamir Khason"
 
If I want (in my case) to work concurrent with (almoust) all tables this
aproach will not be effective at all.
Other ideas?
 
Hi Tamir,

Yes, you can do this by creating a DataAdapter which deals with more than
one table. Please seperate each SQL statement with ';'. Here I wrote a code
snippet which deals with two tables. Each table has a field named "id" and
"a".

sda = new SqlDataAdapter("SELECT * FROM Table11;", this.sqlConnection1);
sda.SelectCommand.CommandText += "SELECT * FROM Table22";

SqlCommand com = new SqlCommand("UPDATE Table11 SET a=@a1 WHERE
id=@id1;", this.sqlConnection1);
com.CommandText += "UPDATE Table22 SET a=@a2 WHERE id=@id2";
com.Parameters.Add("@a1", SqlDbType.VarChar, 50);
com.Parameters.Add("@a2", SqlDbType.VarChar, 50);
com.Parameters.Add("@id1", SqlDbType.Int, 4);
com.Parameters.Add("@id2", SqlDbType.Int, 4);

//Assign values to each parameter.

sda.UpdateCommand = com;

However this is not recommended, because it might be confusing if so many
parameters were added and might not be working properly when using data
binding.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Tamir Khason" <[email protected]>
| References: <#[email protected]>
<u#[email protected]>
| Subject: Re: Update several tables with one dataset update
| Date: Wed, 5 Nov 2003 16:42:15 +0200
| Lines: 31
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 198.211.173.74
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65503
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| If I want (in my case) to work concurrent with (almoust) all tables this
| aproach will not be effective at all.
| Other ideas?
|
|
|
| | > One approach would be to reuse the DataAdapter and create a For Each
| > Datatable in your DataSet loop. Create the appropriate Command and
| related
| > Command properties per each DataTable."Tamir Khason"
| > | > > How can I update several tables (with possible same field names) from
| one
| > > dataset with one data adapter. How to implement it with one
dataadapter.
| I
| > > have about 300 tables to update from the current dataset and I do not
| want
| > > to open 300 data adapters...
| > > Advice
| > >
| > > Cheers,
| > > Tamir Khason
| > >
| > >
| >
| >
|
|
|
 
Back
Top