c#.net 中向SQL数据库保存用户资料怎么写代码啊?

来源:百度知道 编辑:UC知道 时间:2024/06/03 16:59:11
我做了一个网站,用户登陆已经可以连上数据库了,可是注册保存用户信息就连不上数据库,保存不了,点保存按钮就是没有反应,求高手帮忙给个代码给小妹试试

try
{
SqlConnection scon = new SqlConnection("server=.;uid=sa;pwd=;database=ZSW");
scon.Open();
SqlCommand scom = new SqlCommand();
scom.Connection = scon;
scom.CommandText = "insert into UserInfo Values('" + txt1.Text + "','" + txt2.Text + "','" + txt3.Text + "','" + txt4.Text + "','" + txt5.Text + "')";
int count = scom.ExecuteNonQuery();

if (count > 0)
{
MessageBox.Show("添加成功!");
this.Close();
}
else
{
MessageBox.Show("添加失败!");
}
}
catch (Exception ee)