Hi Robb,
There doesn't seem to be problems in your code. However, i cannot reproduce
it, because I don't have the database. I think you can try some steps for
trouble shooting.
1. Please verify if the strong typed dataset schema is the same as the
schema of the database table. (Did you create the dataset by simply drag
the table from the server explorer or did you made some changes to it?) If
you have made some changes, the schema might be different, so that it might
violate the constrants.
2. Try to substitute the following code with a single
SqlCommand.ExecuteScalar. ExecuteScalar returns the first cell of the first
row of the first table. If nothing returned from the database, it returns a
DBNull value.
daDoc.SelectCommand = new SqlCommand(myQuery, icConn);
daDoc.Fill(dsDoc, 0, 1, TblName);
// dsDoc should now have the record containing the highest scan
sequence so we can return it to the caller
if (dsDoc.Tables.Count > 0)
if (dsDoc.Tables[0].Rows.Count > 0)
return (int)dsDoc.Tables[TblName].Rows[0]["ScanSeq"];
You can use:
return selectcommand.ExecuteScalar();
This might be a workaround.
If it still doesn't work, you can post your database table script here. (To
get the table script, click on the table in SQL server, press Ctrl+C, and
press Ctrl+V in a text editer such as notepad.)
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| X-Tomcat-ID: 102372277
| References: <
[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Kevin Yu [MSFT])
| Organization: Microsoft
| Date: Sat, 25 Oct 2003 07:16:51 GMT
| Subject: RE: Failed to enable constraints error...
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Lines: 63
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64530
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Robb,
|
| I cannot reproduce it on my machine according to your statement. I'm not
| quite sure how did you read the record. I would be glad to see the small
| package you built. Please send it to me if you can. Remove "online" from
| the email shown on screen is my mail address.
|
| Kevin Yu
| =======
| "This posting is provided "AS IS" with no warranties, and confers no
| rights."
|
| --------------------
| | Content-Class: urn:content-classes:message
| | From: "Robb Sadler" <
[email protected]>
| | Sender: "Robb Sadler" <
[email protected]>
| | Subject: Failed to enable constraints error...
| | Date: Fri, 24 Oct 2003 11:24:33 -0700
| | Lines: 34
| | Message-ID: <
[email protected]>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="iso-8859-1"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Thread-Index: AcOaXBKUBWhLkdUTQ1mHrGx/5l06xg==
| | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| | Newsgroups: microsoft.public.dotnet.framework.adonet
| | Path: cpmsftngxa06.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.adonet:64506
| | NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| |
| | I have created a dataset which contains a parent child
| | relationship based on a date, machine and batch number.
| |
| | After creating the batch (parent) record,
| |
| | pseudo:
| | new dataset
| | new parentdataadapter
| | new childdataadapter
| |
| | select stmt for parent for one record
| |
| |
| | I am able to successfully create a child record by opening
| | a dataset and first retrieving the batch record, and then
| | creating a child record. However, when I attempt to read
| | the record I just created, I get the following error:
| |
| | "Failed to enable constraints. One or more rows contain
| | values violating non-null, unique, or foreign-key
| | constraints."
| |
| | This record just passed the constraints when I wrote it?!?!
| |
| | I have double checked the key values and they match the
| | parent record. I retrieved the parent record they
| | associate with into the dataset before retrieving the
| | child records. I can't see why this error is coming up.
| |
| | If someone has an "Oh yeah," that would be helpful. I can
| | pull this code out and rework it as a small package if
| | required, but since I have strongly typed datasets, and
| | the table relationships, etc, I figured it is not easily
| | reproduced.
| |
|
|