C#必须声明标量变量 "@username"。请问是哪里错了 5
privatevoidbtn_add_Click(objectsender,EventArgse){stringsql="insertintodbvalues(@user...
private void btn_add_Click(object sender, EventArgs e)
{
string sql = "insert into db values(@username,@dtt,@sex,@mg,@birth,@adr,@tel,@datacard,@cpy,@pte)";
string username = txt_xm.Text;
string dtt = com_dtt.Text;
string mg=" ";
if (rbt_yh.Checked)
{ mg = "已婚"; }
else
{ mg = "未婚"; }
string sex = " ";
if (rbt_man.Checked)
{ sex = "男"; }
else
{ sex = "女"; }
string birth = Convert.ToString(dateTimePicker1.Value);
string adr = txt_adr.Text;
string tel = txt_tel.Text;
string card = txt_datacard.Text;
string cpy = txt_cpy.Text;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(sql,con);
cmd.Parameters.Add(new SqlParameter("@username", username));
cmd.Parameters.Add(new SqlParameter("@dtt", dtt));
cmd.Parameters.Add(new SqlParameter("@sex", sex));
cmd.Parameters.Add(new SqlParameter("@mg", mg));
cmd.Parameters.Add(new SqlParameter("@birth", birth));
cmd.Parameters.Add(new SqlParameter("@adr", adr));
cmd.Parameters.Add(new SqlParameter("@tel", tel));
cmd.Parameters.Add(new SqlParameter("@datacard", card));
cmd.Parameters.Add(new SqlParameter("@cpy", cpy));
cmd.Parameters.Add(new SqlParameter("@pte", path));
Return.ExecuteNonQuery(sql);
GetData();
} 展开
{
string sql = "insert into db values(@username,@dtt,@sex,@mg,@birth,@adr,@tel,@datacard,@cpy,@pte)";
string username = txt_xm.Text;
string dtt = com_dtt.Text;
string mg=" ";
if (rbt_yh.Checked)
{ mg = "已婚"; }
else
{ mg = "未婚"; }
string sex = " ";
if (rbt_man.Checked)
{ sex = "男"; }
else
{ sex = "女"; }
string birth = Convert.ToString(dateTimePicker1.Value);
string adr = txt_adr.Text;
string tel = txt_tel.Text;
string card = txt_datacard.Text;
string cpy = txt_cpy.Text;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(sql,con);
cmd.Parameters.Add(new SqlParameter("@username", username));
cmd.Parameters.Add(new SqlParameter("@dtt", dtt));
cmd.Parameters.Add(new SqlParameter("@sex", sex));
cmd.Parameters.Add(new SqlParameter("@mg", mg));
cmd.Parameters.Add(new SqlParameter("@birth", birth));
cmd.Parameters.Add(new SqlParameter("@adr", adr));
cmd.Parameters.Add(new SqlParameter("@tel", tel));
cmd.Parameters.Add(new SqlParameter("@datacard", card));
cmd.Parameters.Add(new SqlParameter("@cpy", cpy));
cmd.Parameters.Add(new SqlParameter("@pte", path));
Return.ExecuteNonQuery(sql);
GetData();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询