Re: DataTable.select problem with variables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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: Access to SQLServer GCE
    ... Actually, as Larry points out, the Access client does a good job of filtering only information that you need. ... If your query is bound to a report, and you open that report supplying a typical "where" for that report, then Access will NOT pull down all the records, but in most cases Access will only pull down the required records and respect your filter. ... So SQL server will respect the conditions and filtering placed into those queries, and therefore only pull down those records you require. ... The suggestion in these cases is to consider using a pass-through query since all of that summing is done before the row comes down the network pipe. ...
    (comp.databases.ms-access)