primary key problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Irfan

    #1

    primary key problem

    hi,

    when i add a row in a table of a dataset (using dt.rows.add), i expect the
    primary key value to be gernarated automatically as i have set it to
    Autonumber in access. But instead of generating autonumber, it does not do
    anything, which results in null value in the primary key col of new row.

    Although remedy to the above is, not to include the primary key in the
    selectCommand so that Access does it itself. But i need to include the
    primary key in the table because i have to set parent - child relationalship
    with another table.

    Could someone advise please how can the primarykey of a table in a dataset
    to be populated by a unique identifier and not by a null value.

    TIA
    Irfan



  • Cor Ligthert

    #2
    Re: primary key problem

    Irfan,

    Is that table in an existing database or is it a new database?

    Cor


    Comment

    • Irfan

      #3
      Re: primary key problem

      Cor,

      It is an existing database in MS Access, the tables are already created in
      the actual database and now i have transferred them to into dataset.



      irfan

      "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
      news:%23aA4pGod FHA.2776@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Irfan,
      >
      > Is that table in an existing database or is it a new database?
      >
      > Cor
      >[/color]


      Comment

      • Paul Clement

        #4
        Re: primary key problem

        On Tue, 21 Jun 2005 17:22:39 +0100, "Irfan" <irfan@asc-ltd.co.uk> wrote:

        ¤ hi,
        ¤
        ¤ when i add a row in a table of a dataset (using dt.rows.add), i expect the
        ¤ primary key value to be gernarated automatically as i have set it to
        ¤ Autonumber in access. But instead of generating autonumber, it does not do
        ¤ anything, which results in null value in the primary key col of new row.
        ¤
        ¤ Although remedy to the above is, not to include the primary key in the
        ¤ selectCommand so that Access does it itself. But i need to include the
        ¤ primary key in the table because i have to set parent - child relationalship
        ¤ with another table.
        ¤
        ¤ Could someone advise please how can the primarykey of a table in a dataset
        ¤ to be populated by a unique identifier and not by a null value.

        See the following:

        HOW TO: Retrieve the Identity Value While Inserting Records into Access Database By Using Visual
        Basic .NET



        Paul
        ~~~~
        Microsoft MVP (Visual Basic)

        Comment

        • Irfan

          #5
          Re: primary key problem


          This is what i am doing to add a new row,

          Dim dr As DataRow = dtComboBoxdata. NewRow
          'set all columns
          dr("ElementName ") = EleName
          dr("lineloadIDf k") = lineID
          dr("fileIDfk") = fileID
          dtComboBoxdata. Rows.Add(dr)
          da.Update(ds, "comboBoxda ta")

          "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
          news:%23aA4pGod FHA.2776@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > Irfan,
          >
          > Is that table in an existing database or is it a new database?
          >
          > Cor
          >[/color]


          Comment

          • Cor Ligthert

            #6
            Re: primary key problem

            Irfan,

            I am not sure anymore of the missingscheme method helps this, you can try
            it.

            http://msdn.microsoft.com/library/de...ctiontopic.asp

            My idea was not and than you have to add the autoincrement properties.
            http://msdn.microsoft.com/library/de...mberstopic.asp

            If you have this in a parentchildrela tion this is AFAIK a hell of a job,
            because the identifiere in the dataset is not the original one, however a
            substitute. The original one is given at the insert time (and than you can
            find the value of the indentifier as is described at @@Identity in Pauls
            link). I would in this case first create the identifier and than add the
            childs.

            HoweverI prefer to use a Guid as the uniqueidentifie r.

            http://msdn.microsoft.com/library/de...classtopic.asp

            Probably do you have a now a long road to go.

            I hope this helps something.

            Cor




            Comment

            • Irfan

              #7
              Re: primary key problem

              thanks, Cor, seems there is not a short cut.

              I will go through the links, thanks again
              irfan


              "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
              news:e6NjhrodFH A.2736@TK2MSFTN GP12.phx.gbl...[color=blue]
              > Irfan,
              >
              > I am not sure anymore of the missingscheme method helps this, you can try
              > it.
              >
              > http://msdn.microsoft.com/library/de...ctiontopic.asp
              >
              > My idea was not and than you have to add the autoincrement properties.
              > http://msdn.microsoft.com/library/de...mberstopic.asp
              >
              > If you have this in a parentchildrela tion this is AFAIK a hell of a job,
              > because the identifiere in the dataset is not the original one, however a
              > substitute. The original one is given at the insert time (and than you can
              > find the value of the indentifier as is described at @@Identity in Pauls
              > link). I would in this case first create the identifier and than add the
              > childs.
              >
              > HoweverI prefer to use a Guid as the uniqueidentifie r.
              >
              > http://msdn.microsoft.com/library/de...classtopic.asp
              >
              > Probably do you have a now a long road to go.
              >
              > I hope this helps something.
              >
              > Cor
              >
              >
              >
              >[/color]


              Comment

              Working...