how to check sql didn't return anything?

  • Thread starter Thread starter lydia sista via DotNetMonster.com
  • Start date Start date
L

lydia sista via DotNetMonster.com

hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:

myCom as New OledbCommand("select * from product where id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say ds.tables
("product")) there is no row?

I kept getting this error:


Server Error in '/u0201098' Application.
----------------------------------------------------------------------------
----

There is no row at position 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at
position 0.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292


Please help... Thanks..
 
Hello lydia sista via DotNetMonster.com,

IDataReader rdr = myCom.ExecuteReader(CommandBehavior.CloseConnection);

if (rdr.Read())
{
// you got a result
}
else
{
// you didnt
}
 
When you execute the command, you can use a DataReader to iterate over what
was returned and check IF any data was returned.

Dim dr as OleDbDataReader = myCom.ExecuteReader
If dr.HasRows Then
do while dr.Read
examine data here
loop
End If
 
You can't check the rows.count unless you have some rows inside of a table.


Anubhav Mishra said:
u can check the rows count property
Thanks
Anubhav

lydia sista via DotNetMonster.com said:
hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:

myCom as New OledbCommand("select * from product where id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say ds.tables
("product")) there is no row?

I kept getting this error:


Server Error in '/u0201098' Application.
----------------------------------------------------------------------------
----

There is no row at position 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at
position 0.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception
can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292


Please help... Thanks..
 
If the table is there in the dataset you can check the number of rows as the
rows collection count will be 0 if there are no rows, it will throw the
exception if the table is not there in the dataset, which can also be
checked
Thanks
Anubhav
Scott M. said:
You can't check the rows.count unless you have some rows inside of a
table.


Anubhav Mishra said:
u can check the rows count property
Thanks
Anubhav

lydia sista via DotNetMonster.com said:
hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:

myCom as New OledbCommand("select * from product where id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say
ds.tables
("product")) there is no row?

I kept getting this error:


Server Error in '/u0201098' Application.
----------------------------------------------------------------------------
----

There is no row at position 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at
position 0.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception
can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


Please help... Thanks..
 
Hello Anubhav,

You're also assuming that the OP is using a Dataset. The syntax presented
implies a DataReader, in which case Scott's point is valid.

--
Matt Berther
http://www.mattberther.com
If the table is there in the dataset you can check the number of rows
as the
rows collection count will be 0 if there are no rows, it will throw
the
exception if the table is not there in the dataset, which can also be
checked
Thanks
Anubhav
Scott M. said:
You can't check the rows.count unless you have some rows inside of a
table.

u can check the rows count property
Thanks
Anubhav
in message

hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:
myCom as New OledbCommand("select * from product where
id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say
ds.tables
("product")) there is no row?
I kept getting this error:

Server Error in '/u0201098' Application.
-------------------------------------------------------------------
--------- ----

There is no row at position 0.
Description: An unhandled exception occurred during the execution
of the
current web request. Please review the stack trace for more
information
about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: There is no row
at position 0.

Source Error:

An unhandled exception was generated during the execution of the
current
web request. Information regarding the origin and location of the
exception
can be identified using the exception stack trace below.
Stack Trace:

[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandle
r.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292
Please help... Thanks..

-- Message posted via http://www.dotnetmonster.com
 
My point was that you must have a table to have rows. It's a bit easier to
check the .hasRows of a DataReader before you do anything.


Anubhav Mishra said:
If the table is there in the dataset you can check the number of rows as
the rows collection count will be 0 if there are no rows, it will throw
the exception if the table is not there in the dataset, which can also be
checked
Thanks
Anubhav
Scott M. said:
You can't check the rows.count unless you have some rows inside of a
table.


Anubhav Mishra said:
u can check the rows count property
Thanks
Anubhav

message hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:

myCom as New OledbCommand("select * from product where
id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say
ds.tables
("product")) there is no row?

I kept getting this error:


Server Error in '/u0201098' Application.
----------------------------------------------------------------------------
----

There is no row at position 0.
Description: An unhandled exception occurred during the execution of
the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at
position 0.

Source Error:

An unhandled exception was generated during the execution of the
current
web request. Information regarding the origin and location of the
exception
can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


Please help... Thanks..
 
yup u sure can.
lot of ways to do it
DataReader/DataSet
Scott M. said:
My point was that you must have a table to have rows. It's a bit easier
to check the .hasRows of a DataReader before you do anything.


Anubhav Mishra said:
If the table is there in the dataset you can check the number of rows as
the rows collection count will be 0 if there are no rows, it will throw
the exception if the table is not there in the dataset, which can also be
checked
Thanks
Anubhav
Scott M. said:
You can't check the rows.count unless you have some rows inside of a
table.


u can check the rows count property
Thanks
Anubhav

message hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:

myCom as New OledbCommand("select * from product where
id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say
ds.tables
("product")) there is no row?

I kept getting this error:


Server Error in '/u0201098' Application.
----------------------------------------------------------------------------
----

There is no row at position 0.
Description: An unhandled exception occurred during the execution of
the
current web request. Please review the stack trace for more
information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at
position 0.

Source Error:

An unhandled exception was generated during the execution of the
current
web request. Information regarding the origin and location of the
exception
can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


Please help... Thanks..
 
Not to nit-pick, but I wouldn't include DataSet here. A DataSet is a
disconnected data storage mechanism. By the time you get to the DataSet,
you might have already performed several other actions that need not be
performed if there was no data returned in the first place. A DataReader is
a connected data retrieval mechanism. Because it is that much closer to the
actual data, it makes sense (when possible) to check at this level before
going off and performing what would essentially be useless tasks when no
data is present.


Anubhav Mishra said:
yup u sure can.
lot of ways to do it
DataReader/DataSet
Scott M. said:
My point was that you must have a table to have rows. It's a bit easier
to check the .hasRows of a DataReader before you do anything.


Anubhav Mishra said:
If the table is there in the dataset you can check the number of rows as
the rows collection count will be 0 if there are no rows, it will throw
the exception if the table is not there in the dataset, which can also
be checked
Thanks
Anubhav
You can't check the rows.count unless you have some rows inside of a
table.


u can check the rows count property
Thanks
Anubhav

message hi!
I'm new to asp.net
How do you check sql did not return anything?
i mean like if i have an sql like this:

myCom as New OledbCommand("select * from product where
id='sdf'",myConn)

then if there's no product with id sdf, how do i check from myCom?
any idea of what should i do?

-------------------
then just wondering how do you check that in dataset (let's say
ds.tables
("product")) there is no row?

I kept getting this error:


Server Error in '/u0201098' Application.
----------------------------------------------------------------------------
----

There is no row at position 0.
Description: An unhandled exception occurred during the execution of
the
current web request. Please review the stack trace for more
information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row
at
position 0.

Source Error:

An unhandled exception was generated during the execution of the
current
web request. Information regarding the origin and location of the
exception
can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
PartyHouse.searchcatalogue.search_Click(Object s, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


Please help... Thanks..
 
Back
Top