Error : Column values more, data supplied less - How to autogenerate a primary key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shikha1234
    New Member
    • Mar 2008
    • 10

    Error : Column values more, data supplied less - How to autogenerate a primary key

    Hi,

    I have a database which has a primary key field (integer).
    It should be autogenerated on every insert statement.

    I am hardcoding it everytime to remove the error that the data supplied is less but the column values are more.

    command.Command Text = "Insert into abc values(55,'" + strabcName + "','','O')" ;

    This 55 is the primary key which needs to be hardcoded everytime.
    Please help me how can I make it autogenerated everytime
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    If the column in the table is Autogenerated , you need not have to specify it
    while specifying the values in the Insert query.

    e.g. It can be written like this way :

    command.Command Text = "Insert into abc values('" + strabcName + "','','O')" ;


    If you are getting the Database error because of the above insert statement ,please check that the values you are inserting matches to the total no of columns in the table. When you count the value list do not include primary key column into it.



    Originally posted by Shikha1234
    Hi,

    I have a database which has a primary key field (integer).
    It should be autogenerated on every insert statement.

    I am hardcoding it everytime to remove the error that the data supplied is less but the column values are more.

    command.Command Text = "Insert into abc values(55,'" + strabcName + "','','O')" ;

    This 55 is the primary key which needs to be hardcoded everytime.
    Please help me how can I make it autogenerated everytime

    Comment

    Working...