1
Answer

How to solve exception in C#.net

Shomen Deb

Shomen Deb

16y
3.6k
1
I have combobox referring the "Book_id" field of Book table from bookbindingsource dataset. when I select option, I'm shown this message "Column 'Book_id' is constrained to be unique. Value '899866238' is already present." and in the troubleshooting exceptions portion, there is written "Relax or turn off constraints in your DataSets. Make sure you are not trying to assign a value to a primary key field where the primary key already exists in the data table". This is not clear to me. Can anybody help me? Regards, Shomen
Answers (1)
1
Vulpes
NA 98.3k 1.5m 10y
A DataTable in ADO.NET has no concept of a 'current row' because, once it's been populated, it's disconnected from the underlying database. In fact, it doesn't need to have an underlying database at all - it can be created entirely using code!

Once you have your DataTable (dt, say), you can iterate through its DataRows just like any other collection:

foreach(DataRow dr in dt.Rows)
{
   // do something with dr
}

You can also obtain a DataRow directly:

DataRow rowFirst = dt.Rows[0];

DataRow rowLast = dt.Rows[dt.Rows.Count - 1];

It follows that there's no concept of being before the first row or after the last row (BOF or EOF in an ADO RecordSet). You must always be within the row collection itself or you'll get an exception.


0
David Smith
NA 1.9k 0 10y
Thank you so much.