How can i fill the values from one dataadapter to multiple tables in a dataset...ie,the adapter is fetching values through foreach loop...i want to take that values into different tables of one dataset....How to do this...Hope anyone will help me....
SqlDataAdapter adap = new SqlDataAdapter("Select Fecha, Valor from datos where " + strng + " and NumEstacion = @StationID and Fecha between @start_DateTime and @end_DateTime", con2);
string[] strngSep1 = str.Split(';');
ds = new DataSet();
foreach (string strng in strngSep1)
{
SqlDataAdapter adap = new SqlDataAdapter("Select Fecha, Valor from datos where " + strng + " and NumEstacion = @StationID and Fecha between @start_DateTime and @end_DateTime", con2);
adap.SelectCommand.Parameters.Add("@start_DateTime", start_query_date);
adap.SelectCommand.Parameters.Add("@end_DateTime", end_query_date);
adap.SelectCommand.Parameters.Add("@StationID", station_var);
adap.Fill(ds);
}
~ Remember To Mark The Post(s) That Helped You As The ANSWER ~
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
Marked as answer by v-ambily on May 24, 2011 10:39 AM
hai...using this above program the first data is retaining in dataset..according to the next iteration of foreach loop will get another data...so i want to store the first data to one table of dataset and next data to next table of same dataset..at last
i wish to merge into one table....
string[] strngSep1 = str.Split(';');
ds = new DataSet();
int counter =1;
foreach (string strng in strngSep1)
{
SqlDataAdapter adap = new SqlDataAdapter("Select Fecha, Valor from datos where " + strng + " and NumEstacion = @StationID and Fecha between @start_DateTime and @end_DateTime", con2);
adap.SelectCommand.Parameters.Add("@start_DateTime", start_query_date);
adap.SelectCommand.Parameters.Add("@end_DateTime", end_query_date);
adap.SelectCommand.Parameters.Add("@StationID", station_var);
adap.Fill(ds, "Table" + counter.ToString());
counter++;
~ Remember To Mark The Post(s) That Helped You As The ANSWER ~
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
Marked as answer by v-ambily on May 19, 2011 09:30 AM
v-ambily
Member
155 Points
141 Posts
values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 06:38 AM|LINK
Hai,,
How can i fill the values from one dataadapter to multiple tables in a dataset...ie,the adapter is fetching values through foreach loop...i want to take that values into different tables of one dataset....How to do this...Hope anyone will help me....
Thanks in advance
Shakti Singh...
Star
10870 Points
1827 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 07:29 AM|LINK
If your query is fetching data from multiple tables then dataadapter automatically fills them into different tables in dataset. Just use
da.Fill(dataset);
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
v-ambily
Member
155 Points
141 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 07:39 AM|LINK
hai friend,
my query is fetching data from one table,,adapter fetching value is changing as per condition of query through foreach loop
Shakti Singh...
Star
10870 Points
1827 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 07:41 AM|LINK
can you post your code for better understanding??
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
v-ambily
Member
155 Points
141 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 07:46 AM|LINK
string[] strngSep1 = str.Split(';');
foreach (string strng in strngSep1)
{
SqlDataAdapter adap = new SqlDataAdapter("Select Fecha, Valor from datos where " + strng + " and NumEstacion = @StationID and Fecha between @start_DateTime and @end_DateTime", con2);
adap.SelectCommand.Parameters.Add("@start_DateTime", start_query_date);
adap.SelectCommand.Parameters.Add("@end_DateTime", end_query_date);
adap.SelectCommand.Parameters.Add("@StationID", station_var);
ds = new DataSet();
adap.Fill(ds);
}
here how to fill the datas to diifferent table in a dataset in each iteration of foreach
Shakti Singh...
Star
10870 Points
1827 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 08:01 AM|LINK
Initialize dataset outside
string[] strngSep1 = str.Split(';'); ds = new DataSet(); foreach (string strng in strngSep1) { SqlDataAdapter adap = new SqlDataAdapter("Select Fecha, Valor from datos where " + strng + " and NumEstacion = @StationID and Fecha between @start_DateTime and @end_DateTime", con2); adap.SelectCommand.Parameters.Add("@start_DateTime", start_query_date); adap.SelectCommand.Parameters.Add("@end_DateTime", end_query_date); adap.SelectCommand.Parameters.Add("@StationID", station_var); adap.Fill(ds); }Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
v-ambily
Member
155 Points
141 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 08:29 AM|LINK
hai...using this above program the first data is retaining in dataset..according to the next iteration of foreach loop will get another data...so i want to store the first data to one table of dataset and next data to next table of same dataset..at last i wish to merge into one table....
any way of doing like this
Shakti Singh...
Star
10870 Points
1827 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 08:46 AM|LINK
string[] strngSep1 = str.Split(';'); ds = new DataSet(); int counter =1; foreach (string strng in strngSep1) { SqlDataAdapter adap = new SqlDataAdapter("Select Fecha, Valor from datos where " + strng + " and NumEstacion = @StationID and Fecha between @start_DateTime and @end_DateTime", con2); adap.SelectCommand.Parameters.Add("@start_DateTime", start_query_date); adap.SelectCommand.Parameters.Add("@end_DateTime", end_query_date); adap.SelectCommand.Parameters.Add("@StationID", station_var); adap.Fill(ds, "Table" + counter.ToString()); counter++;Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])
v-ambily
Member
155 Points
141 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 09:53 AM|LINK
thank u dear...
can u help me plz once again...how can merge these multiple table into one table of another dataset
Shakti Singh...
Star
10870 Points
1827 Posts
Re: values from one dataadapter to multiple tables in a dataset through foreach loop
May 19, 2011 09:58 AM|LINK
Use DataTable.Merge
Shakti Singh Tanwar
.Net Trainer (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])