從0開始
BlogJava
|
首頁
|
發(fā)新隨筆
|
發(fā)新文章
|
聯(lián)系
|
聚合
|
管理
隨筆:10 文章:86 評論:1 引用:0
對數(shù)據(jù)庫進行“查詢”操作
基于上篇的“增加”操作,現(xiàn)在對增加的數(shù)據(jù)進行查詢。
在“設計頁面”上添加一個GridView控件,如圖:
然后寫代碼如下:
using
System;
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
_Default :Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack )
//
是否是頁面回傳,如果是回傳則不執(zhí)行BindList()方法
{
BindList();
//
頁面第一次運行的時候只需,其余的頁面回傳不執(zhí)行,保證性能;
}
}
private
void
BindList()
{
string
sql
=
"
select * from S_Information
"
;
//
SQL執(zhí)行語句
//
數(shù)據(jù)庫連接字符串
string
connectionString
=
"
server = \
"
.\
"
;DataBase = \
"
student system\
"
;Uid =\
"
sa\
"
;pwd = \
"
sasa\
"
;
"
;
//
反斜杠代表轉意字符
//
建立連接
System.Data.SqlClient.SqlConnection con
=
new
System.Data.SqlClient.SqlConnection(connectionString);
//
建立命令對象
SqlCommand cmd
=
new
SqlCommand(sql, con);
//
建立裝載數(shù)據(jù)的車子
SqlDataAdapter sad
=
new
SqlDataAdapter(cmd);
//
定義數(shù)據(jù)集,車子從SQL數(shù)據(jù)庫里面拉出的數(shù)據(jù)放在這個數(shù)據(jù)集倉庫里面等待使用
DataSet ds
=
new
DataSet();
//
打開連接
con.Open();
//
開始裝載SQL語句所查詢到的數(shù)據(jù)到數(shù)據(jù)集倉庫
sad.Fill(ds);
con.Close();
//
給數(shù)據(jù)綁定控件GridView 指定數(shù)據(jù)
this
.GridView1.DataSource
=
ds;
this
.GridView1.DataBind();
//
執(zhí)行綁定方法
}
}
運行結果如下:
發(fā)表于 2009-10-06 19:43
fanny
閱讀(134)
評論(0)
編輯
收藏
所屬分類:
sql server
<
2025年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
給我留言
查看公開留言
查看私人留言
隨筆檔案
(10)
2009年12月 (10)
文章分類
(84)
c#(13)
(rss)
excel學習(2)
(rss)
html(2)
(rss)
javascript(2)
(rss)
java基礎(23)
(rss)
sql server (11)
(rss)
testing(9)
(rss)
vs .net(22)
(rss)
文章檔案
(86)
2011年1月 (1)
2010年8月 (10)
2010年7月 (1)
2009年12月 (18)
2009年11月 (16)
2009年10月 (3)
2009年1月 (13)
2008年9月 (21)
2008年8月 (3)
收藏夾
(41)
c#(2)
(rss)
DataBase(1)
(rss)
good blog(7)
(rss)
good site(4)
(rss)
Html(1)
(rss)
javascript
(rss)
PC hardware Problem(1)
(rss)
SEO(2)
(rss)
sql server(7)
(rss)
vs . net(16)
(rss)
good blog
GoodSite
My another Blog
浪曦視頻在線
最新隨筆
1.?QTP中的迭代設置
2.?測試用例設計白皮書--測試用例設計綜合策略
3.?軟件測試計劃模板
4.?經典的杯子測試題
5.?如何橫跨兩個工作表來制作下拉菜單
6.?Excel表使用(三):數(shù)據(jù)透視表
7.?筆試題:三角形測試用例設計
8.?筆試題:因果圖法
9.?63個國外優(yōu)秀測試網(wǎng)站地址
10.?用戶名密碼的測試方法(別小看哦)
11.?web測試用例總結
12.?測試內容(轉)
13.?RowDataBound 事件(來自微軟)
14.?SQL COUNT() Function
15.?SCOPE_IDENTITY (Transact-SQL)
搜索
最新評論
1.?re: 求1-100之間的奇數(shù)和、偶數(shù)和[未登錄]
神經,我才四年級
--***
閱讀排行榜
1.?[導入]WF4持久化:SqlWorkflowInstanceStore(351)
2.?[導入]Visual Studio 2010 Ultimate敏捷利劍:詳解Scrum(194)
3.?[導入]調用需要進行身份驗證的Web Service(176)
4.?[導入]挑戰(zhàn):只用一條正則表達式來完成工作(169)
5.?[導入][JavaScript]使用setTimeout減少多余事件(158)
評論排行榜
1.?[導入]挑戰(zhàn):只用一條正則表達式來完成工作(0)
2.?[導入]C#4.0新特性:可選參數(shù),命名參數(shù),Dynamic(0)
3.?[導入]WF4持久化:SqlWorkflowInstanceStore(0)
4.?[導入]調用需要進行身份驗證的Web Service(0)
5.?[導入][JavaScript]使用setTimeout減少多余事件(0)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 fanny
主站蜘蛛池模板:
神木县
|
拉萨市
|
曲沃县
|
宣汉县
|
镇坪县
|
梁平县
|
石景山区
|
宁明县
|
内乡县
|
西宁市
|
朝阳县
|
信丰县
|
九寨沟县
|
西乡县
|
望都县
|
宝清县
|
盘锦市
|
阿合奇县
|
临漳县
|
阿巴嘎旗
|
嵊州市
|
页游
|
图片
|
九龙县
|
芜湖县
|
苗栗县
|
砚山县
|
保定市
|
金堂县
|
徐水县
|
罗山县
|
安平县
|
潼南县
|
琼中
|
平邑县
|
巨鹿县
|
文水县
|
海盐县
|
铜鼓县
|
佛冈县
|
秦皇岛市
|