web开发练习题
} }
2. 通过http://www.77cn.com.cn连接数据库test,并执行一个select * from users查询,将结果通过GridView控件显示出来。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="User.aspx.cs" Inherits="http://www.77cn.com.cner" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.77cn.com.cn/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.77cn.com.cn/1999/xhtml"> <head runat="server"> <title></title> <script runat="server">
protected void Page_Load(object sender, EventArgs e) {
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=myDataBase;Integrated Security=True;Pooling=False"; Conn.Open();
SqlCommand Comm = new SqlCommand("select * from UserTable", Conn); SqlDataReader dr = Comm.ExecuteReader(); gv.DataSource = dr; gv.DataBind(); Conn.Close(); } </script> </head> <body>
<form id="form1" runat="server"> <div>
<asp:GridView ID="gv" runat="server"> </asp:GridView> </div> </form> </body> </html>