用户代码未处理 SqlException
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Threading;
namespace WebApplication1
{
public partial class 户主注册 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["apartmentConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(str);
SqlCommand sqlcommand = new SqlCommand();
sqlcommand.Connection = con;
= "insert into huzhu(hzname,unit,layer,number,hzpassword,) values(@idd,@un,@ly,@num,@hzpass)";
sqlcommand.Parameters.AddWithValue("@idd", TextBox1.Text);
sqlcommand.Parameters.AddWithValue("@un", TextBox2.Text);
sqlcommand.Parameters.AddWithValue("@ly", TextBox3.Text);
sqlcommand.Parameters.AddWithValue("@num", TextBox4.Text);
sqlcommand.Parameters.AddWithValue("@hzpass", TextBox5.Text);
try
{
con.Open();
sqlcommand.ExecuteNonQuery();
Label1.Text = " 注册成功";
Response.Redirect("户主登录.aspx");
}
finally
{
sqlcommand = null;
con.Close();
con = null;
}
}
}
}