注册 登录
编程论坛 C# 论坛

用户代码未处理 SqlException

wxxcrystal 发布于 2014-05-05 22:11, 591 次点击
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;
            }
        }
    }
}
1 回复
#2
asdfv632014-05-06 08:14
这个貌似是没带catch么。。
1