私は既存のIDを持っていますが、このエラーがある場合、 '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