Groups | Blog | Home
all groups > dotnet ado.net > july 2004 >

dotnet ado.net : identities and dataset...


shalafi
7/2/2004 9:18:58 PM
Hi all... got a quick question.

I read in XML to a application dataset variable. since i dont have access
to SQL server i decided to avoid Access and go strait to XML.

Problem i'm having is that when adding a new row i get a constraint issue.

I havent found how to get the PK stored in XML to the point the dataset
recognizes so i do the following after the XML load.

x[0] = theDataStore.Tables["tblArticles"].Columns["ArticleID"];
x[0].AutoIncrement = true;
x[0].AutoIncrementSeed = 0;
x[0].AutoIncrementStep = 1;
theDataStore.Tables["tblArticles"].PrimaryKey = x;

When i try a "newrow()" i get the following.

Column 'ArticleID' is constrained to be unique. Value '1' is already
present.

I didnt get this when i added articleID 1, or when i did articleID 0... but
it seems that the dataset object doesnt see that ArticleID 1 is already in
the DataSet...

Here is the insert code...

public zArticle addArticle(int UserID, int CategoryID)
{
DataRow DR;
zArticle theArticle;

DR = theDataStore.Tables["tblArticles"].NewRow();
DR["UserID"] = UserID;
DR["CategoryID"] = CategoryID;
DR["Headline"] = "";
DR["Body"] = "";
DR["Date"] = DateTime.Now.ToString();

theArticle = new zArticle(int.Parse(DR["ArticleID"].ToString()),
int.Parse(DR["UserID"].ToString()),
int.Parse(DR["CategoryID"].ToString()),
DR["Headline"].ToString(),
DR["Body"].ToString(),
(DateTime) DR["Date"]);
theArticle.update += new zArticle.updateObject(this.updateArticle);

theDataStore.Tables["tblArticles"].Rows.Add(DR);
saveDataStore();
return theArticle;
}



shalafi
7/3/2004 9:38:30 AM
still no deal... it works once when -1 is not in the database, but the
insert after that it fails on.

I can query the dataset to find the max ID and deal with it that way. Just
thought datasets would pick that up and work with it.


[quoted text, click to view]

Miha Markic [MVP C#]
7/3/2004 11:19:59 AM
Hi,

Just set a negative seed and step, -1 and -1.
When you update the table in database you (adapter) should update pk-s with
real value.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

[quoted text, click to view]

AddThis Social Bookmark Button