[newbie]Extracting DataRow from DataSet

G

Guest

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(
 
W

William Ryan eMVP

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 said:
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)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top