Groups | Blog | Home
all groups > dotnet ado.net > january 2007 >

dotnet ado.net : Problems with no rows returning from Query and C#


Bill Gower
1/26/2007 8:36:45 PM
I have code as follows

if((DataTable)read_union_database("retrieveSSN")).row[0][0] == DBNull.Value
{
orow[0] = ""
}
else{
orow[0] = ((Data
Table)read_union_database("retrieveSSN")).rows[0][0].ToString();
}


I keep getting the error "There is no row at position 0" and when I place
debug statements in the code it never goes to the If side of the statement.
The read_union_database is just a SQL query
that returns back the SSN of a member that matches a certain parameter. So
in this case obviously I don't have a match and therefore I don't have a row
being returned. What is the proper way in C# to check to see if that
returned?

Bill

Plamen Ratchev
1/26/2007 9:16:10 PM
Hi Bill,

You can check the DataTable.Rows.Count property. If greater than 0 then you
have some rows returned, otherwise there are no rows.

Regards,

Plamen Ratchev
http://www.SQLStudio.com

Cor Ligthert [MVP]
1/28/2007 11:32:42 AM
Bill,

Is there any reason that there should be a row at position 0 from orow.

I can not get this from the code that you show.

Cor

"Bill Gower" <billgower@charter.net> schreef in bericht
news:u4$IbObQHHA.3412@TK2MSFTNGP05.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button