Identity issues with dataset

S

shalafi

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top