Reputation: 5094
This is my table Produit(ID,libelle,prix)
. The ID is auto increment, and this is the insert instructions :
cmd.Connection = connexion
cmd.CommandText = "INSERT into Produit_fini(libelle,prix) values (@libelle,@prix)"
cmd.Parameters.AddWithValue("@libelle", libelle)
cmd.Parameters.AddWithValue("@prix", prix)
connexion.Open()
cmd.ExecuteNonQuery()
connexion.Close()
After executing that, an error is occured says that I can't insert NULL value to the ID !?
The column can not contain NULL values. [ Column name = ID,Table name = Produit_fini ]
How can I insert the ID here ?
Upvotes: 1
Views: 2429
Reputation: 79929
It seems like this column ID
is not defined with an IDENTITY
property. But, you won't be able to alter the table to add the IDENTITY
property.
You have to delete the table (if there is no data on it), and create it again with the column ID
has IDENTITY(1,1)
.
You might also need to use this tool Compactview to be able to run statements against SQL Server compact edition database.
Upvotes: 1