CurrencyManager.Position ??

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

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