新手请教ASP.NET问题,为什么在下面代码中,数据入不了库,最好能给我段代码,谢谢
//插入个人注册资料
string sql = string.Format("INSERT INTO people(name,password,qq,msn,youxiang,phone) VALUES({0},{1},{2},{3},{4},{5})", this.txtzhanghao.Text, this.txtpass1.Text, this.txtqq.Text, this.txtmsn.Text, this.txtyouxiang.Text, this.txtphone.Text);
SqlConnection con = new SqlConnection("server=RANDY-PC;uid=sa;pwd=happy;database=blog");
SqlCommand com = con.CreateCommand();
com.CommandText = sql;
con.Open();
int result = 0;
try
{
result = com.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
if (result == 1)
{
this.Response.Write("<script type='text/javascript' language='javascript'>alert('注册成功')</script> ");
}
[解决办法]
字段名name是关键字改成[name]