【发布时间】:2016-11-13 09:57:42
【问题描述】:
我为插入用户创建一个页面。
但是当我运行页面时会显示这个错误
ASP 代码
protected void Page_Load(object sender, EventArgs e)
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["shopDBConnectionString"].ConnectionString;
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "insert into tblmember values ('" + txtemail.Text + "','" + txtname.Text + "','" + txtfamily.Text + "','" + txtpass.Text + "','','" + DropDownList1.SelectedValue + "') ";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Default.aspx");
}
【问题讨论】:
-
它清楚地表明您正在将重复值插入主键列。
-
您是否尝试在数据表的主键列中插入重复条目?
-
你的表的主键是什么?
-
没有。哪个重复列?没有重复的列
-
请将您的查询更改为参数化查询,除非您想将自己暴露在 sql 注入攻击中。
标签: c# asp.net sql-server