StrataFrame Forum

Error when Filling Business Object

http://forum.strataframe.net/Topic30963.aspx

By Marcia G Akins - 2/22/2012

Hi All.

This is very bizarre. I am getting this error:

BusinessLayerException
  The CurrentRow for table '[dbo].[cost_types]' could not be evaluated because the CurrentRowIndex is out of range.  Business object record count: 0.  CurrentRowIndex: -1.

Source     : MicroFour StrataFrame Business

Stack Trace:
   at MicroFour.StrataFrame.Business.BusinessLayer.get_CurrentRow()
   at CI_BusinessObjects.boCost_types.get_savings_type_FK() in C:\CI_BusinessObjects\CI_BusinessObjects\boCost_types.Designer.cs:line 283
   at CI_BusinessObjects.boCost_types.GetCostTypesBySavingsType(Int32 SavingsType_FK) in C:\CI_BusinessObjects\CI_BusinessObjects\boCost_types.cs:line 56
   at StlCI_new_winforms.Cost_types.RequeryCosts() in C:\StlCI_new_winforms\StlCI_new_winforms\Cost_types.cs:line 32
   at StlCI_new_winforms.Cost_types.cboSavings_Type_SelectionChangeCommitted(Object sender, EventArgs e) in C:\StlCI_new_winforms\StlCI_new_winforms\Cost_types.cs:line 21
   at System.Windows.Forms.ComboBox.OnSelectionChangeCommitted(EventArgs e)
   at System.Windows.Forms.ComboBox.OnSelectionChangeCommittedInternal(EventArgs e)
   at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at MicroFour.StrataFrame.UI.Windows.Forms.ComboBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

when I try to fill my business object. The current row index SHOULD be zero because the business object has no data. However, this should not be throwing an error.

Any ideas what is wrong? Here is my code:

if (cboSavings_Type.SelectedValue != null)

{

Int32 Savings_Type_PK = Convert.ToInt32(cboSavings_Type.SelectedValue.ToString());

object[] oParms = new object[1];

oParms[0] = Savings_Type_PK;

boCost_types.GetCostTypesBySavingsType(
Convert.ToInt32(cboSavings_Type.SelectedValue.ToString()));

}

TIA

Marcia
By Ivan George Borges - 2/22/2012

Have you had a look at line 56 in your GetCostTypesBySavingsType?
It is likely you are assigning a value to savings_type_FK, but as you said, your BO is empty, so there is no row available.
By Marcia G Akins - 2/22/2012

Ivan George Borges (2/22/2012)
Have you had a look at line 56 in your GetCostTypesBySavingsType?
It is likely you are assigning a value to savings_type_FK, but as you said, your BO is empty, so there is no row available.


This is the line:

FillDataTable("SELECT * FROM cost_types WHERE savings_type_FK = " + savings_type_FK.ToString());

A little more information for you:

When I step into this line of code, it takes me directly here in businesslayer.vb:

<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public ReadOnly Property CurrentRow() As DataRow

Get

If _CurrentRowIndex = -1 Then

Throw New BusinessLayerException("The CurrentRow for table '" & Me.TableNameAndSchema & "' could not be evaluated because the CurrentRowIndex is out of range. Business object record count: " & Me.Count & ". CurrentRowIndex: " & Me._CurrentRowIndex & ".")

Else

Return _CurrentDataTable.DefaultView.Item(_CurrentRowIndex).Row

End If

End Get

End Property

 



By Ivan George Borges - 2/22/2012

There it is, you are using savings_type_FK, which apparently is a field from your empty BO.

FillDataTable("SELECT * FROM cost_types WHERE savings_type_FK = " + savings_type_FK.ToString());
By Marcia G Akins - 2/22/2012

Hi Ivan.

Yep. It was a typo Blush

Thanks for your help.

Marcia
By Ivan George Borges - 2/22/2012

You're welcome, Marcia. Cool