示例#1
0
        protected void btndangky_Click(object sender, EventArgs e)
        {
            TaiKhoan      tk     = new TaiKhoan();
            SqlConnection con    = null;
            string        sqlCon = @"Data Source=DESKTOP-G0I3496\SQLEXPRESS01;Initial Catalog=Nhaccuatui;Integrated Security=True";

            con = new SqlConnection(sqlCon);
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "select*from taikhoan where tendangnhap = @tendn";
            cmd.Parameters.AddWithValue("@tendn", tendangnhap.Text);
            cmd.Connection = con;
            SqlDataReader rd = cmd.ExecuteReader();

            if (rd.HasRows)
            {
                msg.Text      = "tên đăng nhập đã tồn tại";
                msg.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                tk.tendangnhap = tendangnhap.Text;
                tk.matkhau     = matkhau.Text;
                data.ThemTK(tk);
                msg.Text = "Đăng kí thành công";
            }
        }