PC Review


Reply
Thread Tools Rate Thread

DataTable select method behaviour

 
 
Abhishek
Guest
Posts: n/a
 
      6th Dec 2005
Hello,
I was using Datagrid (Windows Forms) the datasource of which was
a DataTable.
If I try to modify or delete some rows from the Datagrid using the
underlying DataTable then
I use Select method of the DataTable to get the corresponding row from the
DataTable.
I use the code as mentioned below:
string strSelect = "TerminalNumber = " + iTermNo;
DataRows[] oRows = oTable.Select(strSelect);

This works fine till the stage when the DataTable has rows less than 10.
However when the
DataTable has rows more than 10 then the select method does not return any
rows even if
the TerminalNumber(if it is 2 digit eg. 10,11,12 etc.) is present in the
Grid/Table.

Is this a bug in Datagrid/DataTable?

It works fine if the code is changed as follows:
string strSelect = "TerminalNumber = '" + iTermNo + "'";
DataRows[] oRows = oTable.Select(strSelect);
i.e. enclosing the iTermNo within single quotes.

Thanks for your help,
Abhishek.


 
Reply With Quote
 
 
 
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      6th Dec 2005
Abhishek - before we go further, this is a keyed table correct?
"Abhishek" <(E-Mail Removed)> wrote in message
news:%23$$fvnn%(E-Mail Removed)...
> Hello,
> I was using Datagrid (Windows Forms) the datasource of which was
> a DataTable.
> If I try to modify or delete some rows from the Datagrid using the
> underlying DataTable then
> I use Select method of the DataTable to get the corresponding row from the
> DataTable.
> I use the code as mentioned below:
> string strSelect = "TerminalNumber = " + iTermNo;
> DataRows[] oRows = oTable.Select(strSelect);
>
> This works fine till the stage when the DataTable has rows less than 10.
> However when the
> DataTable has rows more than 10 then the select method does not return any
> rows even if
> the TerminalNumber(if it is 2 digit eg. 10,11,12 etc.) is present in the
> Grid/Table.
>
> Is this a bug in Datagrid/DataTable?
>
> It works fine if the code is changed as follows:
> string strSelect = "TerminalNumber = '" + iTermNo + "'";
> DataRows[] oRows = oTable.Select(strSelect);
> i.e. enclosing the iTermNo within single quotes.
>
> Thanks for your help,
> Abhishek.
>
>



 
Reply With Quote
 
Abhishek
Guest
Posts: n/a
 
      7th Dec 2005
Yes, this is a keyed table and the Primary key is the same as that given in
the Query, i.e. the TerminalNumber.
However the problem exists. Is there any bug?

"W.G. Ryan - MVP" <(E-Mail Removed)> wrote in message
news:uJ8jRIq%(E-Mail Removed)...
> Abhishek - before we go further, this is a keyed table correct?
> "Abhishek" <(E-Mail Removed)> wrote in message
> news:%23$$fvnn%(E-Mail Removed)...
> > Hello,
> > I was using Datagrid (Windows Forms) the datasource of which

was
> > a DataTable.
> > If I try to modify or delete some rows from the Datagrid using the
> > underlying DataTable then
> > I use Select method of the DataTable to get the corresponding row from

the
> > DataTable.
> > I use the code as mentioned below:
> > string strSelect = "TerminalNumber = " + iTermNo;
> > DataRows[] oRows = oTable.Select(strSelect);
> >
> > This works fine till the stage when the DataTable has rows less than 10.
> > However when the
> > DataTable has rows more than 10 then the select method does not return

any
> > rows even if
> > the TerminalNumber(if it is 2 digit eg. 10,11,12 etc.) is present in the
> > Grid/Table.
> >
> > Is this a bug in Datagrid/DataTable?
> >
> > It works fine if the code is changed as follows:
> > string strSelect = "TerminalNumber = '" + iTermNo + "'";
> > DataRows[] oRows = oTable.Select(strSelect);
> > i.e. enclosing the iTermNo within single quotes.
> >
> > Thanks for your help,
> > Abhishek.
> >
> >

>
>



 
Reply With Quote
 
Abhishek
Guest
Posts: n/a
 
      13th Dec 2005
Anybody with any answers?
Is this a bug or some programming logic error?

"Abhishek" <(E-Mail Removed)> wrote in message
news:%23$$fvnn%(E-Mail Removed)...
> Hello,
> I was using Datagrid (Windows Forms) the datasource of which

was
> a DataTable.
> If I try to modify or delete some rows from the Datagrid using the
> underlying DataTable then
> I use Select method of the DataTable to get the corresponding row from the
> DataTable.
> I use the code as mentioned below:
> string strSelect = "TerminalNumber = " + iTermNo;
> DataRows[] oRows = oTable.Select(strSelect);
>
> This works fine till the stage when the DataTable has rows less than 10.
> However when the
> DataTable has rows more than 10 then the select method does not return any
> rows even if
> the TerminalNumber(if it is 2 digit eg. 10,11,12 etc.) is present in the
> Grid/Table.
>
> Is this a bug in Datagrid/DataTable?
>
> It works fine if the code is changed as follows:
> string strSelect = "TerminalNumber = '" + iTermNo + "'";
> DataRows[] oRows = oTable.Select(strSelect);
> i.e. enclosing the iTermNo within single quotes.
>
> Thanks for your help,
> Abhishek.
>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      13th Dec 2005
Abhishek,

It is strange, it seems that C# converts automaticly a integer to a string
in this case if it is less than 2 digits.

However the prefered method is to use parameters.

Have a look at this sample (it is VB however the only difference with C# in
this are the description of the methods, four declarations and that you have
to add in C# a semicolon at the end)

http://www.vb-tips.com/default.aspx?...a-ae802ee71c86

I hope this helps,

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing SELECT DISTINCT with DataTable.Select method Andrea Caldarone Microsoft ADO .NET 2 30th Jan 2007 09:28 AM
DataTable.Select Method bug? Adrian Microsoft ADO .NET 3 22nd Jun 2006 07:33 AM
Retrieving datarows using DataTable.Select method and adding it to new DataTable C.Anand via DotNetMonster.com Microsoft ADO .NET 4 4th Apr 2005 05:21 PM
DataTable Select method Mandar Patankar via .NET 247 Microsoft ADO .NET 1 30th Mar 2005 11:47 PM
DataTable.Select Method harry Microsoft VB .NET 5 15th Sep 2004 02:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:20 PM.