string int_values="";
foreach(DataRow dr in dataTable.Rows)
{
int_values+=","+dr["col"].ToString();
}
string sqlQuery="select salary in ("+int_values.SubString(1,int_values.Length+") from table A";
if(Hard_Work && Luck)
Response.Write("Success");
Best Of Luck
Shival Thakur
Marked as answer by Kushi Bobby on Apr 13, 2012 07:12 AM
Kushi Bobby
Member
20 Points
29 Posts
Datatable
Apr 13, 2012 04:26 AM|LINK
Hi,
I am having a data table having one column all the time (integers), building from a SQL Command Query with Data adapter.
I want to use those column values in another subquery dynamically like
select salary in (100,200,150..) from tableA
select salary in (datatable) from table A
How to get the list of the the data table column values in the above query as a list.
Arrary list, string array ? pls advice
tej narayan
Member
194 Points
69 Posts
Re: Datatable
Apr 13, 2012 04:41 AM|LINK
you can get the datatable vaues using for loop and dynamically create a sub query
for(int i=0;i<datatble.Rows.Count;i++)
{
int columnvalue=Convert.toint(datatble.Rows[i]["Columnname"]);
Make your subquery here
}
Kushi Bobby
Member
20 Points
29 Posts
Re: Datatable
Apr 13, 2012 05:36 AM|LINK
Hi Tej,
Thanks, But i need the list at a time not the single value.
shivalthakur
Participant
1861 Points
541 Posts
Re: Datatable
Apr 13, 2012 05:41 AM|LINK
Try This
string int_values=""; foreach(DataRow dr in dataTable.Rows) { int_values+=","+dr["col"].ToString(); } string sqlQuery="select salary in ("+int_values.SubString(1,int_values.Length+") from table A";Response.Write("Success");
Best Of Luck
Shival Thakur
Kushi Bobby
Member
20 Points
29 Posts
Re: Datatable
Apr 13, 2012 07:12 AM|LINK
Hi Thakur,
Thanks, that works fine for me.
But with Length-1
string sqlQuery="select salary in ("+int_values.SubString(1,int_values.Length-1+") from table A";