M
Manikandan
Hi,
I have a datatable with rows.
When I used datatable.select with values it is working properly,
But when I use the select with variables it is not working.
I tried with putting '(single quote),"" '(double quote) and many
combination, it is not returning any rows
Sample code for demonstartion
DataTable aDataTable = new DataTable();
aDataTable.Columns.Add("s1", typeof(string));
aDataTable.Columns.Add("s2", typeof(string));
aDataTable.Columns.Add("s3", typeof(string));
aDataTable.Columns.Add("s4", typeof(string));
for(int i=0;i<10;i++)
{
DataRow dr = aDataTable.NewRow();
dr["s1"]=i.ToString();
dr["s2"]=i.ToString();
dr["s3"]=i.ToString();
dr["s4"]=i.ToString();
aDataTable.Rows.Add(dr);
}
string v1="1";
string v2="2";
string qry="s1= '" + v1 + "' AND s2='" + v2 + "'" ;
DataRow[] foundRows=aDataTable.Select(qry);
if(foundRows.Length>0)
{
// process here
}
The above code won't return any rows.
But if I use like this means
string qry="s1='1' AND s2='1'";
It is returning rows(i.e foundRows.Length>0) .
I don't what is the difference between the value and variable in
select statement.
I would like to know,as I'm missing quotes or syntax mistake for
variable in select statement.
Thank You,
Regards,
Mani
I have a datatable with rows.
When I used datatable.select with values it is working properly,
But when I use the select with variables it is not working.
I tried with putting '(single quote),"" '(double quote) and many
combination, it is not returning any rows
Sample code for demonstartion
DataTable aDataTable = new DataTable();
aDataTable.Columns.Add("s1", typeof(string));
aDataTable.Columns.Add("s2", typeof(string));
aDataTable.Columns.Add("s3", typeof(string));
aDataTable.Columns.Add("s4", typeof(string));
for(int i=0;i<10;i++)
{
DataRow dr = aDataTable.NewRow();
dr["s1"]=i.ToString();
dr["s2"]=i.ToString();
dr["s3"]=i.ToString();
dr["s4"]=i.ToString();
aDataTable.Rows.Add(dr);
}
string v1="1";
string v2="2";
string qry="s1= '" + v1 + "' AND s2='" + v2 + "'" ;
DataRow[] foundRows=aDataTable.Select(qry);
if(foundRows.Length>0)
{
// process here
}
The above code won't return any rows.
But if I use like this means
string qry="s1='1' AND s2='1'";
It is returning rows(i.e foundRows.Length>0) .
I don't what is the difference between the value and variable in
select statement.
I would like to know,as I'm missing quotes or syntax mistake for
variable in select statement.
Thank You,
Regards,
Mani