Hi,
I have a sql table having fields ItemID(set as primary key), ItemCategoryID,newid(set as uniqueidentifier)
protected void btnSubmit_Click(object sender, EventArgs e)
{
int ItemID = 1123342;
int ItemCategoryID =1;
}
SqlCommand cmd = new SqlCommand("insert into Item(ItemID,ItemCode,ItemCategoryID,ItemDescription) values(@ItemID,@ItemCategoryID)", con);
cmd.Parameters.AddWithValue("@ItemCode", txtItemCode.Text);
cmd.Parameters.AddWithValue("@ItemDescription", txtItemDescription.Text);
cmd.Parameters.AddWithValue("@ItemID", ItemID);
cmd.Parameters.AddWithValue("@ItemCategoryID",ItemCategoryID);
cmd.ExecuteNonQuery();
}
Whenever I click submit button at first the value will be inserted to db. But in the second click it shows that :
Violation of PRIMARY KEY constraint 'PK_Item'. Cannot insert duplicate key in object 'dbo.aItem'. The duplicate key value is (1123342).
The statement has been terminated.