473,668 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_dsAirplaneTyp es1 is the DataSet
DataTable myTable = m_dsAirplaneTyp es1.AirplaneTyp es;
txtName.DataBin dings.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.DataBi ndings.Add("Tex t", myTable, "at_model") ;
txtLength.DataB indings.Add("Te xt", 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_dsAirplaneTyp es1.AirplaneTyp es.NewRow();

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

// Add to DataSet
m_dsAirplaneTyp es1.AirplaneTyp es.Rows.Add(m_c urrentRow);

// Add to DB
int n = sqlDataAdapter1 .Update(m_dsAir planeTypes1, "AirplaneTypes" );
if (n > 0)
m_dsAirplaneTyp es1.AirplaneTyp es.AcceptChange s();

==> 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 'sqlDataAdapter 1.Update() ' performs well.
}

Any help GREATLY appreciated !!

Chris
Nov 16 '05 #1
1 2522
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.Selec t 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********@pan dora.be> wrote in message
news:vd******** *************@p hobos.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_dsAirplaneTyp es1 is the DataSet
DataTable myTable = m_dsAirplaneTyp es1.AirplaneTyp es;
txtName.DataBin dings.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.DataBi ndings.Add("Tex t", myTable, "at_model") ;
txtLength.DataB indings.Add("Te xt", 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_dsAirplaneTyp es1.AirplaneTyp es.NewRow();

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

// Add to DataSet
m_dsAirplaneTyp es1.AirplaneTyp es.Rows.Add(m_c urrentRow);

// Add to DB
int n = sqlDataAdapter1 .Update(m_dsAir planeTypes1, "AirplaneTypes" );
if (n > 0)
m_dsAirplaneTyp es1.AirplaneTyp es.AcceptChange s();

==> 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 'sqlDataAdapter 1.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
285
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.) what event would one handle to get a handle on things just BEFORE the data is bound. To be clearer, not controlling the formatting of the bound control(backcolor or what have you), but rather control the WAYor even IF the data is bound at all. ...
1
291
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 Form_Load(...) {
3
3146
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, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
6
2308
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 members.organization,artists.artist,artists.email,artists.website,members.email FROM members INNER JOIN artists ON members.memberid=artists.memberid WHERE Notice that both tables involved in the SELECT statement have a field named
1
18835
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 objects that is the datasource of a DataBinding that is bound to a DataGridView (WinForms) then I was expecting that any change to the data would be reflected in the DataGridView (in other words I was expecting the 2 way databinding to actually...
9
2307
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 using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
1
16245
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 Bind() can only be used in the context of a databound control" when I start my page. Unless I'm missing something obvious, this is *not* the same issue as the "2-way databinding cascading lists" issue in...
11
1801
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 adapter.update it gives me 0 records updated! I am not getting any exceptions. Below is the complete code. Someone please help me out. using System; using System.Drawing; using System.Collections; using System.ComponentModel;
1
3467
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 "'System.Data.DataRowView' does not contain a property with the name X" error message which suggests I'm not putting X in the SELECT statement. But this is not the case. If I set the GridView to AutoGenerateColumns="true", it works fine and all the...
0
1306
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 creating these forms, I need to bind controls back to their underlying tables. This has been successful with textboxes, but I am having a lot of difficulty with comboboxes. Setting the datasource to the bindinglist seems to be ok, but I am having...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8572
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2782
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.