Scott
Mon Mar 28 20:03:17 CST 2005
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" <my_email_anubhav.mishra@gmail.com> wrote in message
news:etoct2yMFHA.2384@tk2msftngp13.phx.gbl...
> yup u sure can.
> lot of ways to do it
> DataReader/DataSet
> "Scott M." <s-mar@nospam.nospam> wrote in message
> news:O4b5rsuMFHA.3540@tk2msftngp13.phx.gbl...
>> 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" <my_email_anubhav.mishra@gmail.com> wrote in message
>> news:uMtz4guMFHA.3540@tk2msftngp13.phx.gbl...
>>> 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." <s-mar@nospam.nospam> wrote in message
>>> news:%23Hkd48tMFHA.1268@TK2MSFTNGP14.phx.gbl...
>>>> You can't check the rows.count unless you have some rows inside of a
>>>> table.
>>>>
>>>>
>>>> "Anubhav Mishra" <my_email_anubhav.mishra@gmail.com> wrote in message
>>>> news:OES2%23hoMFHA.2748@TK2MSFTNGP09.phx.gbl...
>>>>>u can check the rows count property
>>>>> Thanks
>>>>> Anubhav
>>>>>
>>>>> "lydia sista via DotNetMonster.com" <forum@DotNetMonster.com> wrote in
>>>>> message news:9bf8342252ca452e94a6a9b093c9bac1@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..
>>>>>>
>>>>>> --
>>>>>> Message posted via
http://www.dotnetmonster.com
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>