我正在将值插入表中,下面是我的代码
protected void Button4_Click(object sender, EventArgs e)
{
string conn = ConfigurationManager.ConnectionStrings["mineConnection"].ConnectionString;
SqlConnection conn1=new SqlConnection(conn);
conn1.Open();
SqlCommand cmd1=new SqlCommand("insert into emp values(@empid,@name)",conn1);
cmd1.Parameters.Add("@empid", TextBox11.Text);
cmd1.Parameters.Add("@name", TextBox12.Text);
SqlDataReader dr;
SqlCommand cmd=new SqlCommand("select * from emp where empid='"+TextBox11.Text+"'",conn1);
dr = cmd.ExecuteReader();
if(dr.HasRows)
{
if(dr.Read())
{
if(TextBox11.Text==dr[0].ToString())
{
Response.Write("id already exists");
}
}
}
else
{
dr.Close();
cmd.ExecuteNonQuery();
Response.Write("values inserted");
}
}
}
但问题是我无法插入这些值,我也没有收到任何错误。有人可以帮我吗?