PC Review


Reply
Thread Tools Rate Thread

[newbie]Extracting DataRow from DataSet

 
 
=?Utf-8?B?V2lsbA==?=
Guest
Posts: n/a
 
      11th Apr 2004
How do I get a datarow from a dataset? I have a datagrid and want to pass the selected datagrid row selected for update to another class to do validation. I get the following exception

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:

Line 158: 'Dim lViewState As System.Web.UI.StateBag = Me.ViewStat
Line 159: 'mDataRow = Me.DsNorthWind_CustOrders1.Tables(0).Rows.Item(mRowIndex
Line 160: mDataRow = Me.DsNorthWind_CustOrders1.Tables(0).Rows(mRowIndex
Line 161: 'send rowindex & datarow to ActivateRule for validatio
Line 162: mActRule.Validate(mRowIndex, mDataRow


Source File: c:\inetpub\wwwroot\ExceptionBeta\WebForm1.aspx.vb Line: 160

Stack Trace:

[IndexOutOfRangeException: There is no row at position 0.
System.Data.DataRowCollection.get_Item(Int32 index
ExceptionBeta.WebForm1.UpdateCommandEventHandler(Object sender, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\ExceptionBeta\WebForm1.aspx.vb:16
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData
System.Web.UI.Page.ProcessRequestMain(




 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      12th Apr 2004
DataSet.Tables[IndexOfTable].Rows[IndexOfRow] should do it for you. From
that exception, it looks like the table doesn't have any rows.

Before you call your function, do a Debug.Assert(DataTable.Rows.Count > 0)
and see what happens.
"Will" <(E-Mail Removed)> wrote in message
news:56DE29CD-35AF-42A1-803F-(E-Mail Removed)...
> How do I get a datarow from a dataset? I have a datagrid and want to pass

the selected datagrid row selected for update to another class to do
validation. I get the following exception:
>
> 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:
>
>
> Line 158: 'Dim lViewState As System.Web.UI.StateBag = Me.ViewState
> Line 159: 'mDataRow =

Me.DsNorthWind_CustOrders1.Tables(0).Rows.Item(mRowIndex)
> Line 160: mDataRow =

Me.DsNorthWind_CustOrders1.Tables(0).Rows(mRowIndex)
> Line 161: 'send rowindex & datarow to ActivateRule for validation
> Line 162: mActRule.Validate(mRowIndex, mDataRow)
>
>
> Source File: c:\inetpub\wwwroot\ExceptionBeta\WebForm1.aspx.vb Line:

160
>
> Stack Trace:
>
>
> [IndexOutOfRangeException: There is no row at position 0.]
> System.Data.DataRowCollection.get_Item(Int32 index)
> ExceptionBeta.WebForm1.UpdateCommandEventHandler(Object sender,

DataGridCommandEventArgs e) in
c:\inetpub\wwwroot\ExceptionBeta\WebForm1.aspx.vb:160
>

System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e)
> System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,

EventArgs e)
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
> System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,

EventArgs e)
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
> System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
>

System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument)
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler

sourceControl, String eventArgument)
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
> System.Web.UI.Page.ProcessRequestMain()
>
>
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2lsbA==?=
Guest
Posts: n/a
 
      12th Apr 2004
Thanks for replying so quickly!!! Hmmm, I tried that and still get the same result (or non-result :-). The "debug" expression returned true when i looked at it via the watch utility in VS . Net. Here's the method minus datarow passing (because I don't even get to the point)
Sub UpdateCommandEventHandler(ByVal sender As Object, ByVal e As DataGridCommandEventArgs
mRowIndex = e.Item.ItemInde
Me.DataGrid1.SelectedIndex = mRowInde
'DataSet.Tables[IndexOfTable].Rows[IndexOfRow
'Me.DsNorthWind_CustOrders1.Tables.Coun
'mRowIndex's value has correct rowindex, I think I'm just missin
'something fundamental of dataset
mDataRow = Me.DsNorthWind_CustOrders1.Tables(0).Rows(mRowIndex
'send rowindex & datarow to ActivateRule for validatio
..
End Su

TIA
 
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
Is DataRow[string] uses DataRow[int] and DataRow[int] much efficient than DataRow[string]? Ryan Liu Microsoft C# .NET 3 2nd Feb 2008 07:14 AM
Dataset doesn't return true when dataset datarow has been modified =?Utf-8?B?QWxwaGE=?= Microsoft C# .NET 3 11th Nov 2005 10:16 PM
Detached datarow and datarow.table brianm@inntec.com Microsoft ADO .NET 3 14th Dec 2004 05:26 PM
create new DataRow, init fields, then set DataRow to UnChanged? Les Caudle Microsoft ADO .NET 2 4th May 2004 05:42 PM
Re: Casting Data.Datarow to a strongly typed datarow CJ Taylor Microsoft VB .NET 4 21st Apr 2004 08:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.