Identity issues with dataset

Discussion in 'ASP .Net' started by shalafi, Jul 2, 2004.

  1. shalafi

    shalafi Guest

    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, Jul 2, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giovanni Bassi
    Replies:
    0
    Views:
    676
    Giovanni Bassi
    Oct 20, 2003
  2. nalbayo
    Replies:
    2
    Views:
    5,600
    Bruce Barker
    Nov 11, 2005
  3. JimLad
    Replies:
    0
    Views:
    470
    JimLad
    Jan 16, 2009
  4. Frederick D'hont
    Replies:
    0
    Views:
    340
    Frederick D'hont
    Jul 25, 2005
  5. Replies:
    6
    Views:
    478
Loading...

Share This Page