问题遇到的现象和发生背景
点击注册后提示有语法错误,哪里有问题呀
问题相关代码,请勿粘贴截图
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
public partial class Reg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string constr = "server=.;DataBase=UserDB;user Id=sa;password=123456";
SqlConnection con = new SqlConnection(constr);
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into userinfo(");
strSql.Append("UserName,Password,Sex,Age,Email,Address,CreatTime)");
strSql.Append("valuse(");
strSql.Append("@uname,@pwd,@sex,@age,@email,@address,@createDate)");
SqlParameter[] parameters ={
new SqlParameter("@uname",SqlDbType.VarChar,20),
new SqlParameter("@pwd",SqlDbType.VarChar,20),
new SqlParameter("@sex",SqlDbType.VarChar,2),
new SqlParameter("@age",SqlDbType.Int),
new SqlParameter("@email",SqlDbType.VarChar,20),
new SqlParameter("@address",SqlDbType.NVarChar,50),
new SqlParameter("@createDate",SqlDbType.DateTime)
};
parameters[0].Value = TextBox1.Text.Trim();
parameters[1].Value = TextBox2.Text.Trim();
parameters[2].Value = RadioButton1.Checked ?"男" : "女";
parameters[3].Value = Convert.ToInt32(TextBox4.Text.Trim());
parameters[4].Value = TextBox5.Text.Trim();
parameters[5].Value = TextBox6.Text.Trim();
parameters[6].Value = System.DateTime.Now.ToShortDateString();
SqlCommand cmd = new SqlCommand(strSql.ToString(),con);
cmd.Parameters.AddRange(parameters);
con.Open();
int n = cmd.ExecuteNonQuery();
con.Close();
if(n > 0)
{
Lable1.Text = "注册成功";
}
else
{
Lable1.Text = "注册失败";
}
}
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
点击注册后应该是这个样子的。