CurrencyManager.Position ??

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

after inserting a record in a DataSet (using .NewRow() and .Add() ) and
commiting it to the DB using the sqlDataAdapter.Update(), do I want to set
the position of my
currency-manager to the last row in the dataSet.
Changing the position is done using the same (working) code that is executed
when I click on a 'btnLast'-button.

void btnLast_Click(..)
{
m_CurrencyManager.Position =
m_dsAirplaneTypes1.AirplaneTypes.Rows.Count -
1;
}

But changing the position (after the insert) results in an exception thrown
:
"Colunm <name of field> is constrained to be unique. Value
<avalue> is already present"

Without the insert, so just navigating around : no problem.

who can help me please ?
thnx
Chris

class MyForm : System.Windows.Forms.Form
{
private CurrencyManager m_CurrencyManager;
private DataRow m_currentRow;

void frmAirplaneTypes_Load(...)
{
DataTable myTable = m_dsAirplaneTypes1.AirplaneTypes;
m_CurrencyManager = (CurrencyManager)this.BindingContext[myTable];

// m_dsAirplaneTypes1 is my dataSet-object
}
void Insert_Click(...)
{
m_currentRow = m_dsAirplaneTypes1.AirplaneTypes.NewRow();
// Edit fields
m_currentRow["at_typeid"] = txtTypeID.Text.Trim();
m_currentRow["at_name"] = txtName.Text.Trim();
// Add to DataSet
m_dsAirplaneTypes1.AirplaneTypes.Rows.Add(m_currentRow);

// Commit to DB
sqlDataAdapter1.Update(m_dsAirplaneTypes1, "AirplaneTypes");

// Go to last record
btnLast_Click(..);
}

void btnLast_Click(..)
{
m_CurrencyManager.Position =
m_dsAirplaneTypes1.AirplaneTypes.Rows.Count - 1;
==> THIS IS GENERATING THE EXCEPTION
} // btnLast_Click()
} // class
 
Chris,

Is that column auto-generated on the data set? Or rather, is it an
identity column that the server generates? If so, are you sure that it is
being updated correctly when you call update? Basically, are you sure that
you the identity constraint is not being violated, like it says?

Hope this helps.
 
Back
Top