how to insert PK automatically?

  • i want primary key of table to be inserted automatically. i've set its in desgin table as Identity = Yes; Seed=1

    i want my application all other attributes except primary key which i've set atutomatically inserted.

     

    but by doing this; it doesn't insert its value. instead it enters 0

     

    can u plz help me in doing so?

  • can you post your DDL ?

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • CREATE TABLE [BillPayment] (

     [billpaymentId] [int] IDENTITY (1, 1) NOT NULL ,

     [billPaymentDate] [datetime] NULL ,

     [newBillBalance] [float] NULL ,

     [billAmount] [float] NULL ,

     CONSTRAINT [PK_BillPayment] PRIMARY KEY  CLUSTERED

     (

      [billpaymentId]

    &nbsp  ON [PRIMARY]

    ) ON [PRIMARY]

    GO

  • Works fine overhere ...

    CREATE TABLE [BillPayment] (

     [billpaymentId] [int] IDENTITY (1, 1) NOT NULL ,

     [billPaymentDate] [datetime] NULL ,

     [newBillBalance] [float] NULL ,

     [billAmount] [float] NULL ,

     CONSTRAINT [PK_BillPayment] PRIMARY KEY  CLUSTERED

     (

      [billpaymentId]

    &nbsp ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    insert into BillPayment default values

    go

    insert into BillPayment default values

    go

    select * from BillPayment

    go

    -- billpaymentId billPaymentDate                                        newBillBalance                                        billAmount                                           

    -- ------------- ------------------------------------------------------ ----------------------------------------------------- -----------------------------------------------------

    -- 1             NULL                                                   NULL                                                  NULL

    -- 2             NULL                                                   NULL                                                  NULL

    --

    -- (2 row(s) affected)

    --

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Can you post your insert statement as well?

    You should also make sure SET IDENTITY INSERT isn't set to ON


    I keep a close watch on this data of mine, I keep a connection to the database open all the time...

    Gianni Cache

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply