我想顯示一個信息框說'身份證存在,插入不成功',如果我有一個現有的ID,但有這個錯誤!違反PRIMARY KEY不能在對象'dbo.EventType'中插入重複鍵。重複的鍵值是(6)
protected void Button1_Click(object sender, EventArgs e)
{
int result = 0;
EventType produ = new EventType(int.Parse(tb_id.Text), tb_Name.Text);
result = produ.EventTypeInsert();
if (produ == null)
{
if (result > 0)
{
Response.Write("<script>alert('Insert successful');</script>");
}
else
{
Response.Write("<script>alert('Insert NOT successful');</script>");
}
}
else
{
Response.Write("<script>alert('ID already exists.Insert NOT successful');</script>");
}
}
你有沒有試過調試以發現你爲什麼會遇到「錯誤」的情況? –
[違反PRIMARY KEY約束]的可能重複(https://stackoverflow.com/questions/6796009/violation-of-primary-key-constraint) – VDWWD