请教asp.net插入数据库的问题

来源:百度知道 编辑:UC知道 时间:2024/05/23 20:40:38
protected void btnNext2_Click(object sender, EventArgs e)
{

try
{
SqlConnection con = MyDB.creatConnection();
con.Open();
string sql = "insert into login (userName,userPwd) values('" + pid.Text + " '" + pwd.Text + "'')";
SqlCommand cmd = new SqlCommand("sql, con");
cmd.ExecuteNonQuery();
con.Close();
}
catch
{
Response.Write("插入失败!");
}

}
请问以上代码有问题吗?为什么总显示插入失败?

string sql = "insert into login (userName,userPwd) values('" + pid.Text + "','" + pwd.Text + "')";
SqlCommand cmd = new SqlCommand(sql, con);
---------------------------------------------
落叶枫晨小说网http://www.joytxt.com/,打造免费小说新纪元