473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DataBinding generates exception ???

Hi,

I have a DB-table 'AirplaneTypes' that has to 2 fields that form the primary
key :
'at_name' and 'at_model'
both in the DB defined as type : char 15

MyWinform client :

void Form_Load(...) {
// m_dsAirplaneTypes1 is the DataSet
DataTable myTable = m_dsAirplaneTypes1.AirplaneTypes;
txtName.DataBindings.Add("Text", myTable, "at_name");
==> when this databind is executed will an exception be thrown from
the moment I perform an 'AcceptChanges' on my DataSet (see
below)

If this binding is not executed at Form_Load() :
no exception thrown by 'AcceptChanges' (???)

// Following DataBindings don't create any problems (only the
previous??)
txtModel.DataBindings.Add("Text", myTable, "at_model");
txtLength.DataBindings.Add("Text", myTable, "at_length");
}

Below is the buttonInsert-click event that will generate an exception, not
after I
enter values for the first time :
txtName.Text = "1" txtModel.Text = "1" txtLength.Text = "1"
but when entering values the 2nd time :
txtName.Text = "2" txtModel.Text = "2" txtLength.Text= "2"

void btnInsert_Click(...) {
m_currentRow = m_dsAirplaneTypes1.AirplaneTypes.NewRow();

// Edit the fields
m_currentRow["at_name"] = txtName.Text.Trim();
m_currentRow["at_model"] = txtModel.Text.Trim();
m_currentRow["at_length"] = txtLength.Text.Trim();

// Add to DataSet
m_dsAirplaneTypes1.AirplaneTypes.Rows.Add(m_curren tRow);

// Add to DB
int n = sqlDataAdapter1.Update(m_dsAirplaneTypes1, "AirplaneTypes");
if (n > 0)
m_dsAirplaneTypes1.AirplaneTypes.AcceptChanges();

==> EXCEPTION thrown when I execute the 2nd time (and I enter

different values !!)
"Column 'at_name, at_model' is constrained to be unqiue.
Value '2, 2' is already present"

BUT THE DATA HAS BEEN ENTERED IN THE DB CORRECTLY !
So 'sqlDataAdapter1.Update() ' performs well.
}

Any help GREATLY appreciated !!

Chris
Nov 16 '05 #1
1 2493
Chris, AcceptChange will end any existing edits out there, so if you had a
row in edit mode, it wouldn't be sent back to the db so the update would
work, when you call AcceptChanges, it will end the edit, reset the rowstate
etc. Make sure that the current edit is finished before calling update b/c
I think the value may be getting into the db, then when you try
AcceptChanges, it's trying to add what's already there.. Before you call
AcceptChanges, do a DataTable.Select on the primary key
http://www.knowdotnet.com/articles/adopartiii.html and see if that value
already exists. You may just need to do an endcurrentedit or EndEdit method
before calling update. http://www.knowdotnet.com/articles/adopartiii.html
"Chris" <ch********@pandora.be> wrote in message
news:vd*********************@phobos.telenet-ops.be...
Hi,

I have a DB-table 'AirplaneTypes' that has to 2 fields that form the primary key :
'at_name' and 'at_model'
both in the DB defined as type : char 15

MyWinform client :

void Form_Load(...) {
// m_dsAirplaneTypes1 is the DataSet
DataTable myTable = m_dsAirplaneTypes1.AirplaneTypes;
txtName.DataBindings.Add("Text", myTable, "at_name");
==> when this databind is executed will an exception be thrown from the moment I perform an 'AcceptChanges' on my DataSet (see
below)

If this binding is not executed at Form_Load() :
no exception thrown by 'AcceptChanges' (???)

// Following DataBindings don't create any problems (only the
previous??)
txtModel.DataBindings.Add("Text", myTable, "at_model");
txtLength.DataBindings.Add("Text", myTable, "at_length");
}

Below is the buttonInsert-click event that will generate an exception, not
after I
enter values for the first time :
txtName.Text = "1" txtModel.Text = "1" txtLength.Text = "1"
but when entering values the 2nd time :
txtName.Text = "2" txtModel.Text = "2" txtLength.Text= "2"

void btnInsert_Click(...) {
m_currentRow = m_dsAirplaneTypes1.AirplaneTypes.NewRow();

// Edit the fields
m_currentRow["at_name"] = txtName.Text.Trim();
m_currentRow["at_model"] = txtModel.Text.Trim();
m_currentRow["at_length"] = txtLength.Text.Trim();

// Add to DataSet
m_dsAirplaneTypes1.AirplaneTypes.Rows.Add(m_curren tRow);

// Add to DB
int n = sqlDataAdapter1.Update(m_dsAirplaneTypes1, "AirplaneTypes");
if (n > 0)
m_dsAirplaneTypes1.AirplaneTypes.AcceptChanges();

==> EXCEPTION thrown when I execute the 2nd time (and I enter

different values !!)
"Column 'at_name, at_model' is constrained to be unqiue.
Value '2, 2' is already present"

BUT THE DATA HAS BEEN ENTERED IN THE DB CORRECTLY !
So 'sqlDataAdapter1.Update() ' performs well.
}

Any help GREATLY appreciated !!

Chris

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason S | last post by:
I haven't been able to get an answer to this in the asp.net group, hoping someone here can enlighten me. As pertains to databinding a control in a repeating fashion(datagrid, repeater, etc.)...
1
by: Chris | last post by:
Hi, I have a DB-table 'AirplaneTypes' that has to 2 fields that form the primary key : 'at_name' and 'at_model' both in the DB defined as type : char 15 MyWinform client : void...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
6
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
1
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business...
9
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables...
1
by: Owen Blacker | last post by:
I've spent loads of time Googling to try to work this one out and I'm sure it's something obvious. I get an InvalidOperationException reading "Databinding methods such as Eval(), XPath(), and...
11
by: =?Utf-8?B?R29rdWw=?= | last post by:
I am struck up with a problem and want anyone here to help me out. I am a beginner in .NET trying to learng DataBinding concepts. I have binded 4 text boxes with a dataset but when I say...
1
by: Mundo | last post by:
Hi I'm pulling my hair out with a problem caused when DataBinding a DataSet to a web control. I first tried using a GridView but when that failed, I tried a Repeater. I'm getting the classic...
0
by: theleshie | last post by:
Hi, I am creating an application which dynamically creates forms depending on the information held in a dataset (which also includes the data the application itself uses). As part of dynamically...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.