84
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> GridView:<br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="masp" HeaderText="Mã SP" /> <asp:BoundField DataField="tensanpham" HeaderText="Tên sản phẩm" /> <asp:ImageField DataImageUrlField="hinhanh"> </asp:ImageField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='< %#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <EmptyDataTemplate>

Ôn tập KTTMDT

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> GridView:<br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="masp" HeaderText="Mã SP" /> <asp:BoundField DataField="tensanpham" HeaderText="Tên sản phẩm" /> <asp:ImageField DataImageUrlField="hinhanh"> </asp:ImageField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='<%#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <EmptyDataTemplate> Không có dữ liệu </EmptyDataTemplate> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" />

Page 2: Ôn tập KTTMDT

</asp:GridView> <br /> Repeater:<br /> <br /> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table cellspacing="0" cellpadding="4" border="0" id="GridView1" style="color:#333333;border-collapse:collapse;">

<tr style="color:White;background-color:#507CD1;font-weight:bold;">

<th scope="col">M&#227; SP</th><th scope="col">T&#234;n sản phẩm</th><th scope="col">&nbsp;</th><th scope="col">&nbsp;</th>

</tr></HeaderTemplate>

<ItemTemplate><tr style="background-color:#EFF3FB;">

<td><%#Eval("masp") %></td><td><%#Eval("tensanpham") %></td><td><img src='<%#Eval("hinhanh") %>' style="border-

width:0px;" /></td><td><asp:Button ID="Button2" runat="server"

CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='<%#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td>

</tr> </ItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater> <br /> DataList:<br /> <br /> <asp:DataList ID="DataList1" runat="server" style="margin-right: 2px" RepeatDirection="Horizontal"> <ItemTemplate> <table>

<tr style="background-color:#EFF3FB;"><th>Mã SP</th><td><%#Eval("masp") %></td>

</tr><tr style="background-color:#EFF3FB;"> <th scope="col">Tên sản phẩm</th>

<td><%#Eval("tensanpham") %></td></tr><tr style="background-color:#EFF3FB;"> <th scope="col">Hình ảnh</th>

Page 3: Ôn tập KTTMDT

<td><img src='<%#Eval("hinhanh") %>' style="border-width:0px;" /></td>

</tr><tr style="background-color:#EFF3FB;"> <th scope="col">Mua hàng</th> <td><asp:Button ID="Button2" runat="server"

CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='<%#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td> </tr>

</table> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:ThanhPhoConn %>" SelectCommand="SELECT * FROM [vidu_gridview]"></asp:SqlDataSource> </div> File DFF<br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <br /> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" ontextchanged="TextBox1_TextChanged"></asp:TextBox> </form></body></html>

Page 4: Ôn tập KTTMDT

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;using System.IO;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; CoSoDuLieu cs = new CoSoDuLieu(); DataSet dataSet = cs.docDataSet("select * from vidu_gridview"); GridView1.DataSource = dataSet.Tables[0]; GridView1.DataBind(); Repeater1.DataSource = dataSet.Tables[0]; Repeater1.DataBind(); DataList1.DataSource = dataSet.Tables[0]; DataList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Button a = (Button)sender;//Chuyển sender thành đối tượng Button để lấy CommandName. Response.Write(a.CommandName + " "+ a.ToolTip); a.BackColor = System.Drawing.Color.Green; } protected void TextBox1_TextChanged(object sender, EventArgs e) { Response.Write(TextBox1.Text); }}

Page 5: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> GridView:<br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="masp" HeaderText="Mã SP" /> <asp:BoundField DataField="tensanpham" HeaderText="Tên sản phẩm" /> <asp:ImageField DataImageUrlField="hinhanh"> </asp:ImageField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='<%#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <EmptyDataTemplate> Không có dữ liệu </EmptyDataTemplate> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" />

Page 6: Ôn tập KTTMDT

</asp:GridView> <br /> Repeater:<br /> <br />

<asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table cellspacing="0" cellpadding="4" border="0" id="GridView1" style="color:#333333;border-collapse:collapse;">

<tr style="color:White;background-color:#507CD1;font-weight:bold;">

<th scope="col">M&#227; SP</th><th scope="col">T&#234;n sản phẩm</th><th scope="col">&nbsp;</th><th scope="col">&nbsp;</th>

</tr></HeaderTemplate>

<ItemTemplate><tr style="background-color:#EFF3FB;">

<td><%#Eval("masp") %></td><td><%#Eval("tensanpham") %></td><td><img src='<%#Eval("hinhanh") %>' style="border-

width:0px;" /></td><td><asp:Button ID="Button2" runat="server"

CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='<%#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td>

</tr> </ItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater> <br /> DataList:<br /> <br /> <asp:DataList ID="DataList1" runat="server" style="margin-right: 2px" RepeatDirection="Horizontal"> <ItemTemplate> <table>

<tr style="background-color:#EFF3FB;"><th>Mã SP</th><td><%#Eval("masp") %></td>

</tr><tr style="background-color:#EFF3FB;"> <th scope="col">Tên sản phẩm</th>

<td><%#Eval("tensanpham") %></td></tr><tr style="background-color:#EFF3FB;"> <th scope="col">Hình ảnh</th>

Page 7: Ôn tập KTTMDT

<td><img src='<%#Eval("hinhanh") %>' style="border-width:0px;" /></td>

</tr><tr style="background-color:#EFF3FB;"> <th scope="col">Mua hàng</th> <td><asp:Button ID="Button2" runat="server"

CausesValidation="false" CommandName='<%#Eval("masp")%>' ToolTip='<%#Eval("tensanpham")%>' Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td> </tr>

</table> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ThanhPhoConn %>" SelectCommand="SELECT * FROM [vidu_gridview]"></asp:SqlDataSource> </div> File DFF<br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <br /> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" ontextchanged="TextBox1_TextChanged"></asp:TextBox> </form></body></html>

Page 8: Ôn tập KTTMDT

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;using System.IO;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; CoSoDuLieu cs = new CoSoDuLieu(); DataSet dataSet = cs.docDataSet("select * from vidu_gridview"); GridView1.DataSource = dataSet.Tables[0]; GridView1.DataBind(); Repeater1.DataSource = dataSet.Tables[0]; Repeater1.DataBind(); DataList1.DataSource = dataSet.Tables[0]; DataList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Button a = (Button)sender;//Chuyển sender thành đối tượng Button để lấy CommandName. Response.Write(a.CommandName + " "+ a.ToolTip); a.BackColor = System.Drawing.Color.Green; } protected void TextBox1_TextChanged(object sender, EventArgs e) { Response.Write(TextBox1.Text); }}

Page 9: Ôn tập KTTMDT

using System;using System.Data;using System.Data.SqlClient;using System.Collections.Generic;using System.Linq;using System.Web;public class DBAccess{

public DBAccess(){

// TODO: Add constructor logic here}

public SqlConnection con = null; public void KetNoi() { con = new SqlConnection(); con.ConnectionString = "Data Source=MRCOFFEE-PC\\SQLEXPRESS;InitialCatalog=qlsv;Integrated Security=True"; con.Open(); }

public SqlDataReader xulyExecuteReader(string query) { SqlCommand da = new SqlCommand(query, con); SqlDataReader result = da.ExecuteReader(); return result; }

public DataSet xulyDataset(string query) { KetNoi(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); con.Close(); return ds; }

public void xulyExecuteNoneQuery(string query) { KetNoi(); SqlCommand da = new SqlCommand(query, con); da.ExecuteNonQuery(); con.Close(); }}

Page 10: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Upload.aspx.cs" Inherits="Upload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server" enctype="multipart/form-data"> <div> <asp:FileUpload ID="fuNhac" runat="server" /> <br /> <asp:FileUpload ID="fuNhac0" runat="server" /> <br /> <asp:FileUpload ID="fuNhac1" runat="server" /> <br /> <asp:FileUpload ID="fuNhac2" runat="server" /> <br /> <asp:FileUpload ID="fuNhac3" runat="server" /> <br /> <br /> <asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click" /> </div> </form></body></html>

Page 11: Ôn tập KTTMDT

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;

public partial class Upload : System.Web.UI.Page{

protected void Page_Load(object sender, EventArgs e) { }

protected void btnUpload_Click(object sender, EventArgs e) { string currentDirectory = Server.MapPath("~/"); string fileName; for (int i = 0; i < 5; i++) { HttpPostedFile file = Request.Files[i];

if (file.ContentLength > 0)

{

fileName = file.FileName;

System.IO.FileInfo fi = new System.IO.FileInfo(currentDirectory + fileName);

if (fi.Exists)

file.SaveAs(currentDirectory + fileName + "123");

else

file.SaveAs(currentDirectory + fileName);

Page 12: Ôn tập KTTMDT

}

//Response.Write(currentDirectory + fileName);

}

}

}

Page 13: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataSet.aspx.cs" Inherits="DataSet" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> #form1 { width: 343px; } </style></head><body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form></body></html>

Page 14: Ôn tập KTTMDT

using System;using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.OleDb;

public partial class DataSet : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

OleDbConnection con = new OleDbConnection();

con.ConnectionString = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"D:\\BT ASP.NET\\Login\\DataLogin.accdb\"";

//Mo ket noi

con.Open();

//Doc du lieu ra DataSet

string OleDb = "SELECT * FROM HANG";

Page 15: Ôn tập KTTMDT

OleDbDataAdapter sda = new OleDbDataAdapter(OleDb, con);

DataSet ds = new DataSet();

//sda.Fill(ds);

//Dan du lieu vao GridView de hien thi

GridView1.DataSource = ds.Table[0];

GridView1.DataBind();

//Dong ket noi

con.Close();

}

}

Page 16: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Log In</title>

<style type="text/css">

.style1

{

}

.style2

{

width: 109px;

}

#form1

{

width: 556px;

}

.style3

{

width: 355px;

}

</style>

Page 17: Ôn tập KTTMDT

</head>

<body>

<form id="form1" runat="server">

<table style="width:81%; margin-left: 0px; height: 257px;" border=1>

<tr>

<td colspan="2">

<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

ĐĂNG NHẬP HỆ THỐNG&nbsp;</b></td>

</tr>

<tr>

<td class="style2">

User Name</td>

<td class="style3">

<asp:TextBox ID="txtUserName" runat="server"

Width="126px" style="margin-left: 0px"></asp:TextBox>

<asp:RequiredFieldValidator ID="rfvTaiKhoan" runat="server"

ControlToValidate="txtUserName" ErrorMessage="Tai khoan khong duoc bo trong"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class="style2">

Page 18: Ôn tập KTTMDT

Pass Word</td>

<td class="style3">

<asp:TextBox ID="txtPassWord" runat="server" Width="121px" TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator ID="rfvPassWord" runat="server"

ControlToValidate="txtPassWord" ErrorMessage="Pass Word khong duoc bo trong"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class="style1" colspan="2">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<asp:Label

ID="lbTB" runat="server" style="color: #FF0000; text-align: center"></asp:Label>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:CheckBox ID="cbGhiNho" runat="server" Text="Ghi nho tai khoan"

style="text-align: center" />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<br />

Page 19: Ôn tập KTTMDT

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<asp:Button ID="btxDangNhap" runat="server" onclick="btxDangNhap_Click"

Text="DangNhap" style="text-align: center" />

</td>

</tr>

</table>

</form>

</body>

</html>

Page 20: Ôn tập KTTMDT

using System;using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (Request.Cookies["UserName"] != null && Request.Cookies["PassWord"] != null)

{

string un = Request.Cookies["UserName"].Value;

string pw = Request.Cookies["PassWord"].Value;

//Kết nối được với CSDL

SqlConnection con = new SqlConnection();

Page 21: Ôn tập KTTMDT

con.ConnectionString = @"Data Source=NGOCCHUNG-PC\SQLEXPRESS;Initial Catalog=WEBSITE;Integrated Security=True";

con.Open();

//Thao tac voi CSDL

string sql = " SELECT *"

+ " FROM THANH_VIEN"

+ " WHERE (UserName = '" + un + "') AND "

+ " ([PassWord] = '" + pw + "') ";

SqlDataAdapter sqlDA = new SqlDataAdapter(sql, con);

DataSet DS = new DataSet();

sqlDA.Fill(DS);

if (DS.Tables[0].Rows.Count > 0)

{

Session["HoTen"] = DS.Tables[0].Rows[0]["HoTen"].ToString();

Response.Redirect("Welcome.aspx");

}

}

}

protected void btxDangNhap_Click(object sender, EventArgs e)

{

//Kết nối được với CSDL

SqlConnection con = new SqlConnection();

con.ConnectionString = @"Data Source=NGOCCHUNG-PC\SQLEXPRESS;Initial Catalog=WEBSITE;Integrated Security=True";

con.Open();

Page 22: Ôn tập KTTMDT

//Thao tac voi CSDL

string sql = " SELECT *"

+ " FROM THANH_VIEN"

+ " WHERE (UserName = '" + txtUserName.Text + "') AND "

+ " ([PassWord] = '" + txtPassWord.Text + "') ";

SqlDataAdapter sqlDA = new SqlDataAdapter(sql, con);

DataSet DS = new DataSet();

sqlDA.Fill(DS);

if (DS.Tables[0].Rows.Count > 0)

{

if (cbGhiNho.Checked == true)

{

HttpCookie ckun = new HttpCookie("UserName");

ckun.Value = txtUserName.Text;

ckun.Expires = DateTime.Today.AddDays(1);

Response.Cookies.Add(ckun);

HttpCookie ckpw = new HttpCookie("PassWord");

ckpw.Value = txtPassWord.Text;

ckpw.Expires = DateTime.Today.AddDays(1);

Response.Cookies.Add(ckpw);

}

Session["HoTen"] = DS.Tables[0].Rows[0]["HoTen"].ToString();

Response.Redirect("Welcome.aspx");

Page 23: Ôn tập KTTMDT

}

else

{

lbTB.Text = "Nhập sai tài khoản hoặc password!";

}

//Dong ket noi

con.Close();

}

}

Page 24: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MatHang.aspx.cs" Inherits="MatHang" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

<style type="text/css">

.style1

{

width: 415px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<table style="width: 52%;">

<tr>

<td colspan="2">

BẢNG NHẬP HÀNG</td>

</tr>

<tr>

<td>

Mã Hàng</td>

Page 25: Ôn tập KTTMDT

<td class="style1">

<asp:TextBox ID="txtMaHang" runat="server"

Width="388px"></asp:TextBox>

</td>

</tr>

<tr>

<td>

Tên Hàng</td>

<td class="style1">

<asp:TextBox ID="txtTenHang" runat="server" Width="387px"></asp:TextBox>

</td>

</tr>

<tr>

<td colspan="2">

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;<asp:Button ID="btNhap" runat="server" onclick="btNhap_Click"

Text="Nhap Hang" />

</td>

</tr>

</table>

Page 26: Ôn tập KTTMDT

</form>

</body>

</html>

Page 27: Ôn tập KTTMDT

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.OleDb;

public partial class MatHang : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void btNhap_Click(object sender, EventArgs e)

{

//Kết nối được với CSDL

Page 28: Ôn tập KTTMDT

OleDbConnection con = new OleDbConnection();

con.ConnectionString = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"D:\\BT ASP.NET\\Login\\DataLogin.accdb\"";

try

{

con.Open();

//Thao tac voi CSDL

string query = " INSERT INTO HANG(MaHang, TenHang) VALUES ('" + txtMaHang.Text + "' , '" + txtTenHang.Text + "') ";

OleDbCommand cmd = new OleDbCommand();

cmd.CommandText = query;

cmd.Connection = con;

object tenHang = cmd.ExecuteScalar();

Response.Write("Ban da cap nhat thanh cong: " + tenHang + "(" + txtTenHang.Text + ")");

//Dong ket noi

con.Close();

} catch { Response.Write("Cap nhat khong thanh cong."); } }

}

Page 29: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SinhVien.aspx.cs" Inherits="SinhVien" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

</form>

</body>

</html>

Page 30: Ôn tập KTTMDT

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class SinhVien : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

////Ket noi CSDl

//string ConnectionString = @"Data Source=NGOC_CHUNG;Initial Catalog=QL_WEBSITE;Integrated Security=True";

//SqlConnection sqlConn = new SqlConnection(ConnectionString);

////Mo ket noi

// sqlConn.Open();

////Doc du lieu ra DataSet

Page 31: Ôn tập KTTMDT

// string sqlCmd = "SELECT * FROM SINH_VIEN";

// SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCmd, sqlConn);

// DataSet DS = new DataSet();

// sqlDA.Fill(DS);

////Dan du lieu vao GridView de hien thi

//GridView1.DataSource = DS.Tables[0];

//GridView1.DataBind();

////Dong ket noi

//sqlConn.Close();

}

}

Page 32: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TracNghiem.aspx.cs" Inherits="TracNghiem" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

<style type="text/css">

.style1

{

width: 583px;

}

.style2

{

width: 283px;

}

.style3

{

width: 283px;

height: 19px;

}

.style4

{

Page 33: Ôn tập KTTMDT

width: 583px;

height: 19px;

}

.style5

{

height: 19px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<table style="width:100%;">

<tr>

<td colspan="3">

&nbsp;&nbsp; TRAC NGHIEM KIEN THUC&nbsp;</td>

</tr>

<tr>

<td class="style2">

HINH ANH</td>

<td class="style1">

NOI DUNG</td>

<td >

&nbsp;</td>

</tr>

Page 34: Ôn tập KTTMDT

<tr>

<td class="style3">

</td>

<td class="style4">

&nbsp;</td>

<td class="style5">

CAU HOI</td>

</tr>

<tr>

<td class="style2">

&nbsp;</td>

<td class="style1">

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

</table>

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

<br />

</form>

</body>

Page 35: Ôn tập KTTMDT

</html>

Page 36: Ôn tập KTTMDT

using System;using System.Collections;

using System.Configuration;

using System.Data;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

public partial class TracNghiem : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (IsPostBack) return;

String query = "SELECT ID_CAU_HOI FROM CAU_HOI";

DataSet ds = new DataSet(); //docDataSet(query);

for (int i = 0; i < ds.Tables.Count; i++)

{

Button bt = new Button();

bt.ID = ds.Tables[0].Rows[i]["ID_CAU_HOI"]+"";

bt.Text = "Cau hoi " + (i+1);

hienThiNut.Controls.Add(bt);

Page 37: Ôn tập KTTMDT

}

}

public DataSet docDataSet(string ChuoiTruyVan)

{

//Ket noi CSDl

string ConnectionString = @"Data Source=NGOC_CHUNG;Initial Catalog=QL_WEBSITE;Integrated Security=True";

SqlConnection sqlConn = new SqlConnection(ConnectionString);

//Mo ket noi

sqlConn.Open();

SqlDataAdapter sqlDA = new SqlDataAdapter(ChuoiTruyVan, sqlConn);

DataSet DS = new DataSet();

sqlDA.Fill(DS);

sqlConn.Close();

return DS;

}

}

Page 38: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Welcome.aspx.cs" Inherits="Welcome" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Welcome</title>

<style type="text/css">

.style1

{

color: #FF0000;

font-weight: bold;

}

.style2

{

text-align: center;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<div>

<table style="width: 43%;" border=1>

<tr>

Page 39: Ôn tập KTTMDT

<td class="style2">

&nbsp;

<span class="style1">THONG BAO!!!!!!!!!</span></td>

</tr>

<tr>

<td>

&nbsp;

<b>

<asp:Label ID="lblTen" runat="server"

style="text-align: center; color: #3333FF"></asp:Label>

</b>

</td>

</tr>

<tr>

<td>

<asp:Button ID="btLogout" runat="server" onclick="btLogout_Click"

style="text-align: center" Text="Log Out" />

</td>

</tr>

</table>

</div>

</form>

Page 40: Ôn tập KTTMDT

</body>

</html>

Page 41: Ôn tập KTTMDT

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class Welcome : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (Session["HoTen"] != null)

{

lblTen.Text = "Chao mung ban *** " + Session["HoTen"] + " *** da tham gia vao WebSite.";

}

}

Page 42: Ôn tập KTTMDT

protected void btLogout_Click(object sender, EventArgs e)

{

Session["HoTen"] = null;

HttpCookie ckun = new HttpCookie("UserName");

ckun.Expires = DateTime.Now;

Response.Cookies.Add(ckun);

HttpCookie ckpw = new HttpCookie("PassWord");

ckpw.Expires = DateTime.Now;

Response.Cookies.Add(ckpw);

Response.Redirect("Login.aspx");

}

}

Page 43: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

<style type="text/css">

.style1

{

width: 188px;

}

.style3

{

width: 162px;

}

.style4

{

width: 188px;

height: 35px;

}

.style5

{

Page 44: Ôn tập KTTMDT

height: 35px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<asp:Repeater ID="rpSinhVien" runat="server">

<ItemTemplate>

<table style="width: 54%; height: 162px; margin-left: 0px;" border = "1">

<tr>

<td class="style3" rowspan="4">

<img src="images/<%#Eval ("HINH_ANH") %>" />

</td>

<td class="style4">

Ma Sinh Vien</td>

<td class="style5">

<%#Eval ("MA_SINH_VIEN") %></td>

</tr>

<tr>

<td class="style1">

Ho Ten</td>

<td>

<%#Eval ("HO_TEN") %></td>

</tr>

Page 45: Ôn tập KTTMDT

<tr>

<td class="style1">

Ngay Sinh</td>

<td>

<%#Eval ("NGAY_SINH") %></td>

</tr>

<tr>

<td class="style1">

Ten Lop</td>

<td>

<%#Eval ("TEN_LOP") %></td>

</tr>

</table>

</ItemTemplate>

</asp:Repeater>

</form>

</body>

</html>

using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;

Page 46: Ôn tập KTTMDT

using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string sql = "SELECT SINH_VIEN.MA_SINH_VIEN,SINH_VIEN.HO_TEN, SINH_VIEN.NGAY_SINH, LOP.TEN_LOP, HINH_ANH"

+ " FROM SINH_VIEN INNER JOIN"

+ " LOP ON SINH_VIEN.MA_LOP =LOP.MA_LOP";

LopKetNoi kn = new LopKetNoi();

DataSet ds = kn.XuLyDataSet(sql);

rpSinhVien.DataSource = ds.Tables[0];

rpSinhVien.DataBind();

}

}

Page 47: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="MuaHang.aspx.cs" Inherits="MuaHang" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Mua Hang</title>

<style type="text/css">

.style1

{

color: #FF0000;

font-weight: bold;

text-align: center;

}

.style2

{

}

.style3

{

width: 111px;

}

</style>

</head>

Page 48: Ôn tập KTTMDT

<body>

<form id="form1" runat="server">

<div>

<table style="width: 23%;" border=1>

<tr>

<td class="style1" colspan="2">

THONG KE</td>

</tr>

<tr>

<td class="style3">

So SP</td>

<td>

<asp:Label ID="lbSP" runat="server" Text="0"></asp:Label>

</td>

</tr>

<tr>

<td class="style3">

So Tien</td>

<td>

<asp:Label ID="lbST" runat="server" Text="0"></asp:Label>

</td>

</tr>

<tr>

Page 49: Ôn tập KTTMDT

<td class="style2" colspan="2">

<asp:Button ID="btXem" runat="server" Text="Xem Hang" onclick="btXem_Click" />

</td>

</tr>

</table>

<br />

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">

<Columns>

<asp:BoundField DataField="MaSo" HeaderText="Mã Số" />

<asp:BoundField DataField="TenHang" HeaderText="Tên Hàng" />

<asp:BoundField DataField="NgaySX" HeaderText="Ngày Sản Xuất" />

<asp:BoundField DataField="DonGia" HeaderText="Đơn Giá" />

<asp:ImageField DataImageUrlField="HinhAnh"

DataImageUrlFormatString="./images/{0}" HeaderText="Hinh Anh">

</asp:ImageField>

<asp:TemplateField HeaderText="Mua Hàng">

<ItemTemplate>

<asp:Button CommandName= '<%#Eval("DonGia") %>' ToolTip = '<%#Eval("TenHang") %>' ID="Button1" runat="server" Text="Mua Hang"

onclick="Button1_Click" />

</ItemTemplate>

</asp:TemplateField>

Page 50: Ôn tập KTTMDT

</Columns>

</asp:GridView>

<br />

</div>

</form>

</body>

</html>

Page 51: Ôn tập KTTMDT

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class MuaHang : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection();

con.ConnectionString = @"Data Source=NGOCCHUNG-PC\SQLEXPRESS;Initial Catalog=WEBSITE;Integrated Security=True";

con.Open();

//Doc du lieu ra DataSet

string sql = "SELECT * FROM SAN_PHAM";

Page 52: Ôn tập KTTMDT

SqlDataAdapter sda = new SqlDataAdapter(sql, con);

DataSet ds = new DataSet();

sda.Fill(ds);

//Dan du lieu vao GridView de hien thi

GridView1.DataSource = ds.Tables[0];

GridView1.DataBind();

//Dong ket noi

con.Close();

}

protected void Button1_Click(object sender, EventArgs e)

{

Button bt = (Button)sender;

Response.Write("Ban da kich vao nut mua hang: "+ bt.CommandName + bt.ToolTip);

lbSP.Text = "" + (Convert.ToInt32(lbSP.Text) + 1);

lbST.Text = "" + (Convert.ToInt32(lbST.Text) + Convert.ToInt32(bt.CommandName));

}

protected void btXem_Click(object sender, EventArgs e)

{

}

}

Page 53: Ôn tập KTTMDT

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MuaHang2.aspx.cs" EnableEventValidation="false" Inherits="MuaHang2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Mua Hang</title>

</head>

<body>

<form id="form1" runat="server">

<asp:Repeater ID="Repeater1" runat="server">

<HeaderTemplate>

<table style="width: 66%;" border="1">

<tr>

<td>

Mã Số</td>

<td>

Tên Hàng</td>

<td>

Ngày Sản Xuất</td>

<td>

Đơn Giá</td>

<td>

Page 54: Ôn tập KTTMDT

Hình Ảnh</td>

<td>

Mua Hàng</td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr>

<td>

<%#Eval ("MaSo") %></td>

<td>

<%#Eval ("TenHang") %></td>

<td>

<%#Eval ("NgaySX") %></td>

<td>

<%#Eval ("DonGia") %></td>

<td>

<img src="images/<%#Eval ("HinhAnh") %>" /></td>

<td>

<asp:Button CommandName= '<%#Eval("MaSo") %>' ToolTip = '<%#Eval("TenHang") %>' ID="Button1" runat="server" Text="Mua Hang"

onclick="Button1_Click" /></td>

</tr>

</ItemTemplate>

<FooterTemplate> </table></FooterTemplate>

Page 55: Ôn tập KTTMDT

</asp:Repeater>

</form>

</body>

</html>

Page 56: Ôn tập KTTMDT

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class MuaHang2 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection();

con.ConnectionString = @"Data Source=NGOCCHUNG-PC\SQLEXPRESS;Initial Catalog=WEBSITE;Integrated Security=True";

con.Open();

//Doc du lieu ra DataSet

string sql = "SELECT * FROM SAN_PHAM";

SqlDataAdapter sda = new SqlDataAdapter(sql, con);

Page 57: Ôn tập KTTMDT

DataSet ds = new DataSet();

sda.Fill(ds);

//Dan du lieu vao GridView de hien thi

Repeater1.DataSource = ds.Tables[0];

Repeater1.DataBind();

//Dong ket noi

con.Close();

}

protected void Button1_Click(object sender, EventArgs e)

{

Button bt = (Button)sender;

Response.Write("Ban da kich vao nut mua hang: " + bt.CommandName + bt.ToolTip);

}

}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MuaHang3.aspx.cs" EnableEventValidation="false" Inherits="MuaHang3" %>

Page 58: Ôn tập KTTMDT

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Mua Hang 3</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:DataList ID="DataList1" runat="server" Width="982px">

<HeaderTemplate>

<table style="width: 66%;" border="1">

<tr>

<td>

Mã Số</td>

<td>

Tên Hàng</td>

<td>

Ngày Sản Xuất</td>

<td>

Đơn Giá</td>

<td>

Hình Ảnh</td>

Page 59: Ôn tập KTTMDT

<td>

Mua Hàng</td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr>

<td>

<%#Eval ("MaSo") %></td>

<td>

<%#Eval ("TenHang") %></td>

<td>

<%#Eval ("NgaySX") %></td>

<td>

<%#Eval ("DonGia") %></td>

<td>

<img src="images/<%#Eval ("HinhAnh") %>" /></td>

<td>

<asp:Button CommandName= '<%#Eval("MaSo") %>' ToolTip = '<%#Eval("TenHang") %>' ID="Button1" runat="server" Text="Mua Hang"

onclick="Button1_Click" /></td>

</tr>

</ItemTemplate>

<FooterTemplate> </table></FooterTemplate>

Page 60: Ôn tập KTTMDT

</asp:DataList>

</div>

</form>

</body>

</html>

Page 61: Ôn tập KTTMDT

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class MuaHang3 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

SqlCommand.

SqlConnection con = new SqlConnection();

con.ConnectionString = @"Data Source=NGOCCHUNG-PC\SQLEXPRESS;Initial Catalog=WEBSITE;Integrated Security=True";

con.Open();

//Doc du lieu ra DataSet

string sql = "SELECT * FROM SAN_PHAM";

Page 62: Ôn tập KTTMDT

SqlDataAdapter sda = new SqlDataAdapter(sql, con);

DataSet ds = new DataSet();

sda.Fill(ds);

//Dan du lieu vao GridView de hien thi

DataList1.DataSource = ds.Tables[0];

DataList1.DataBind();

//Dong ket noi

con.Close();

}

protected void Button1_Click(object sender, EventArgs e)

{

Button bt = (Button)sender;

Response.Write("Ban da kich vao nut mua hang: "+ bt.CommandName + bt.ToolTip);

}

}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TimDiem.aspx.cs" Inherits="TimDiem" %>

Page 63: Ôn tập KTTMDT

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

<style type="text/css">

.style1

{

}

.style2

{

width: 206px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<table style="width:61%;" border = "1">

<tr>

<td class="style1">

<asp:DropDownList ID="ddlLop" runat="server" DataTextField="TEN_LOP"

DataValueField="MA_LOP">

</asp:DropDownList>

Page 64: Ôn tập KTTMDT

</td>

<td class="style2">

<asp:DropDownList ID="ddlMonHoc" runat="server" DataTextField="TEN_MON"

DataValueField="MA_MON">

</asp:DropDownList>

</td>

<td>

<asp:Button ID="btTim" runat="server" Text=" TIM KIEM" />

</td>

</tr>

<tr>

<td class="style1" colspan="3">

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

</td>

</tr>

</table>

</form>

</body>

</html>

using System;

using System.Collections;

Page 65: Ôn tập KTTMDT

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class TimDiem : System.Web.UI.Page

{

LopKetNoi lkn = new LopKetNoi();

protected void Page_Load(object sender, EventArgs e)

{

if (IsPostBack) return;

DataSet ds=lkn.XuLyDataSet(

}

}

Page 66: Ôn tập KTTMDT

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

/// <summary>

/// Summary description for LopKetNoi

/// </summary>

public class LopKetNoi

{

public LopKetNoi()

{

//

// TODO: Add constructor logic here

//

Page 67: Ôn tập KTTMDT

}

public SqlConnection sqlConn = null;

public SqlConnection KetNoi()

{

string sql_con = @"Data Source=NGOCCHUNG-PC\SQLEXPRESS;Initial Catalog=WEBSITE;Integrated Security=True";

sqlConn = new SqlConnection(sql_con);

sqlConn.Open();

return sqlConn;

}

public SqlDataReader XuLyExecuteReader(string query)

{

KetNoi();

SqlCommand da = new SqlCommand(query, sqlConn);

SqlDataReader result = da.ExecuteReader();

return result;

}

public DataSet XuLyDataSet(string query)

{

KetNoi();

SqlDataAdapter da = new SqlDataAdapter(query, sqlConn);

Page 68: Ôn tập KTTMDT

DataSet ds = new DataSet();

da.Fill(ds);

sqlConn.Close();

return ds;

}

public void XuLyExecuteNonQuery(string query)

{

KetNoi();

SqlCommand da = new SqlCommand(query, sqlConn);

da.ExecuteNonQuery();

sqlConn.Close();

}

}