SQL サーバーにデータを挿入しようとしていますが、「PRIMARY KEY 制約 'PK_login1' の違反。オブジェクト 'dbo.login1' に重複したキーを挿入できません。ステートメントは終了しました。」のようなエラー メッセージが表示されます。テーブルから主キー制約を削除しようとしましたが、その後、2 つ以上の同様の種類のデータがテーブルに挿入されていることがわかりました。私のコードは
protected void btn_Submit_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd;
str = "Insert into login1 values ('" + txtbx_Uname.Text + "', '" + txtbx_Pwd.Text + "', '" + txtbx_Email.Text + "', '" + txtbx_Dob.Text + "', " + txtbx_Phone.Text + ")";
con.Open();
cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
lbl_Error.Visible = true;
lbl_Error.Text = "Registration Success";
int n = Convert.ToInt32(cmd.ExecuteScalar());
if(n==1)
Response.Redirect("Login.aspx");
con.Close();
}
catch
{
lbl_Error.Visible = true;
lbl_Error.Text = "SQL Server Error. Pleaase try after sometime";
}
}