0% found this document useful (0 votes)
103 views4 pages

T o M T L P Thao Tác V I CSDL Using Using Using Using Using Using Using Public Class Public

This document defines a class called clsDatabase that contains methods for connecting to a SQL database, executing queries, counting records, loading data into grid views and drop down lists. It also includes code for button click events to add, update and delete records from a table called TaiKhoan using the methods in the clsDatabase class.

Uploaded by

theanh1990
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views4 pages

T o M T L P Thao Tác V I CSDL Using Using Using Using Using Using Using Public Class Public

This document defines a class called clsDatabase that contains methods for connecting to a SQL database, executing queries, counting records, loading data into grid views and drop down lists. It also includes code for button click events to add, update and delete records from a table called TaiKhoan using the methods in the clsDatabase class.

Uploaded by

theanh1990
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

To mt lp thao tc vi csdl using using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Data.SqlClient; System.

Data; System.Web.UI.WebControls;

public class clsDatabase { public clsDatabase() { // // TODO: Add constructor logic here // } // khai bo chui kt ni static string connectionString = @"Data Source=.;Initial Catalog=DangKy;Integrated Security=True"; SqlConnection con; SqlCommand cmd; //SqlDataReader dr; SqlDataAdapter da; //phng thc kt ni public void KetNoi() { con = new SqlConnection(connectionString); if (con.State == ConnectionState.Closed) con.Open(); } public void NgatKetNoi() { con.Close(); } // thc thi cu lnh QSL public void ThucThi(string Select) { KetNoi(); cmd = new SqlCommand(Select, con); cmd.ExecuteNonQuery(); NgatKetNoi(); } // m s bn ghi public int SoBanGhi(string select)

{ KetNoi(); cmd = new SqlCommand(select, con); int SBG = (int)(cmd.ExecuteScalar()); NgatKetNoi(); return SBG; } // Load d liu Ln gridview public void LoadGV(string select, GridView gv) { KetNoi(); DataTable dt = new DataTable(); da = new SqlDataAdapter(select, con); da.Fill(dt); gv.DataSource = dt; gv.DataBind(); NgatKetNoi(); } // Load du lieu len DropDownList public void LoadComBoBox(DropDownList dc, string select,string hien,string an) { DataTable dt = new DataTable(); da = new SqlDataAdapter(select, con); da.Fill(dt); dc.DataSource = dt; dc.DataTextField = hien; dc.DataValueField = an; dc.DataBind(); } } Vit code cho cc nt Thm, Sa Xa , Load du Liu ln Gridview, DropDownList 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.Data; public partial class _Default : System.Web.UI.Page { clsDatabase db = new clsDatabase(); protected void Page_Load(object sender, EventArgs e)

{ if (!IsPostBack) { db.KetNoi(); // load ln GridView db.LoadGV("select * from TaiKhoan", gvsinhvien); // Load Ln DropDownList db.LoadComBoBox(cbload, "Select * from TaiKhoan ", "TenDN", "MatKhau"); db.NgatKetNoi(); } } // s kin Mi protected void Mi_Click(object sender, EventArgs e) { txtghichu.Text=""; txtmatkhau.Text=""; txttendangnhap.Text=""; } // s kin thm protected void Them_Click(object sender, EventArgs e) { string Them="insert into TaiKhoan values ('"+txttendangnhap.Text.Trim()+"','"+txtmatkhau.Text+"','"+txtghichu.T ext+"')"; db.ThucThi(Them); } // s kin sa protected void Sua_Click(object sender, EventArgs e) { string Sua = "Update TaiKhoan set MatKhau='" + txtmatkhau.Text.Trim() + "',GhiChu='" + txtghichu.Text.Trim() + "' where TenDN='" + txttendangnhap.Text.Trim() + "' "; db.ThucThi(Sua); } // s kin xa protected void xoa_Click(object sender, EventArgs e) { string Xoa = "Delete from TaiKhoan where TenDN='" + txttendangnhap.Text.Trim() + "'"; db.ThucThi(Xoa); } protected void cbload_SelectedIndexChanged(object sender, EventArgs e) {

} }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy