我目前正在执行帐户注册页面,但我不断收到错误system.data.sqlclient.sqlexception。 “地址”附近的语法不正确。编码有什么问题?
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from [UserData] where UserName='" + TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp ==1)
{
MessageBox.Show("User Already Exists.");
}
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into [UserData] (Username,Email Address,Password,Phone Number,Full Name,Home Address) values (@Username,@EmailAddress,@Password,@PhoneNumber,@FullName,@HomeAddress)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@Username", TextBoxUN.Text);
com.Parameters.AddWithValue("@EmailAddress", TextBoxEmail.Text);
com.Parameters.AddWithValue("@Password", TextBoxPass.Text);
com.Parameters.AddWithValue("@PhoneNumber", TextBoxPhone.Text);
com.Parameters.AddWithValue("@FullName", TextBoxFull.Text);
com.Parameters.AddWithValue("@HomeAddress", TextBoxHome.Text);
com.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
MessageBox.Show("Registration is successful!");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error:"+ ex.ToString());
}
}