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>
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库make--Web开发练习题(16)在线全文阅读。
相关推荐: