DataTable.Select cannot find DataRow

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I call Select on a DataTable looking for a particular DataRow. I can look

at the DataRow 'manually' and see that it exists:

Command Window

?dssearch.Tables("names").Rows(7)("names_id")

"030587" {String}

String: "030587"

I doubled checked the RowState:

?dssearch.Tables("names").Rows(7).RowState

Unchanged



However, when I look for it at runtime like this:

Command Window

?dsSearch.Tables("names").Select("names_id = 030587", "",

DataViewRowState.CurrentRows)

{Length=0}

The call cannot find the DataRow. I tried qualifying the pk with '', but

that did not work.

This has worked for every case except this id: "030587".

What am I missing here?



Greg Robinson

I'm a blogger: http://dotnetrocks.blogspot.com/
 
have you tried running the same select statement against
the database? What happens if you leave off the leading
Zero?

Shane
 
Greg,
Try single quotes around that string value. i.e. names_id = '030587'
Ron Allen
 
Sane, yes, in query analyzer I find the record.

Turns out I really did need to wrap it with ticks ''. However. doing
this causes all other searches to fail.

So, I just added an else for when the search does not return a DataRow,
try it again with ticks this time.

Very strange behavior though. I too think is has something to do with
the leading zero.
 
-----Original Message-----
I call Select on a DataTable looking for a particular DataRow. I can look

at the DataRow 'manually' and see that it exists:

Command Window

?dssearch.Tables("names").Rows(7)("names_id")

"030587" {String}

String: "030587"

I doubled checked the RowState:

?dssearch.Tables("names").Rows(7).RowState

Unchanged



However, when I look for it at runtime like this:

Command Window

?dsSearch.Tables("names").Select("names_id = 030587", "",

DataViewRowState.CurrentRows)

{Length=0}

The call cannot find the DataRow. I tried qualifying the pk with '', but

that did not work.

This has worked for every case except this id: "030587".

What am I missing here?



Greg Robinson

I'm a blogger: http://dotnetrocks.blogspot.com/


.


Greg Try this;

Dim nRow() As DataRow
Dim irow As Integer
nRow = tblCaseDocs.Select("doc_dte_due = '" &
holdDte.ToString & "'")

For irow = 0 To nRow.GetUpperBound(0)
Debug.WriteLine(vbTab & nRow(irow)("case_id"))
ListBox1.Items.Add(nRow(irow)("case_id")
& " " & nRow(irow)("Document_nme"))
Next

Gordon
 
Hi,

Since it is a string datatype, then you have to warp your value into single
quotes. Depending on datatype you would need to wrap some values. For
example dates require # as a wrapper #01/01/2003#
 
Back
Top