Re: DataTable.select problem with variables



On May 1, 11:29 am, "Jon Skeet [C# MVP]" <s...@xxxxxxxxx> wrote:
On May 1, 11:24 am, Manikandan <plmanikan...@xxxxxxxxx> wrote:

<snip>

I would like to know,as I'm missing quotes or syntax mistake for
variable in select statement.

Your code is trying to find rows with s1=1 and s2=2. There are no rows
matching that query, because for each of your test rows, s1=s2.

Jon

Hi,
Sorry i mistakenly used
string v2="2";
It's also "1"
only
i.e string v2="1";

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="1";
string qry="s1= '" + v1 + "' AND s2='" + v2 +
"'" ;
DataRow[] foundRows=aDataTable.Select(qry);
if(foundRows.Length>0)
{
// process here
}


I'm actually taking the values from database(sql server) and using in
select statement.
For demonstration only i used above code, is there any chance of
problem from sql server 2000


Thank You,
Regards,
Mani

.



Relevant Pages

  • Re: Help with JOins
    ... I have these queries and i want to JOIN all of them to make one query. ... the usual recommendation is to post the ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (microsoft.public.sqlserver.mseq)
  • Re: Extracting Duplicates from SQL Server 2000
    ... Here is the query that I used. ... a few well-chosen rows of sample data (as ... My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis ...
    (comp.databases.ms-sqlserver)
  • Re: DataTable.select problem with variables
    ... matching that query, because for each of your test rows, s1=s2. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: CONTAINS performance
    ... That said, and with the query plan, I can start to give you more ... relational join in the context of the free-text optimization, ... SQL Server tables. ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Indexing Service, Openquery and sp_executesql
    ... SQL Server version and sp are you running? ... > data from the indexing service catalog when pasted into ... > query analyzer, but failed when put against sp_executesql ... I would choose Microsoft Indexing ...
    (microsoft.public.sqlserver.fulltext)