All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET生成静态HTML页面并分别按年月目录存放_.net资料_编程技术
PHP初学者:配置Apache服务器并且设置DNS_php资料_编程技术
C#操作MySQL中文乱码的解决方案_[Asp.Net教程]
PHP动态网页程序中常用的表单验证类_[PHP教程]
Delphi执行sql server模糊查询
浅谈SQL,Server,2008中的行压缩_mssql学习_编程技术
apache中httpd.conf的中文件详解_php资料_编程技术
ASP.NET,2.0移动开发之设备筛选器的应用_[Asp.Net教程]
对标题中特殊字符格式化,以便能换行显示_[Asp.Net教程]
SQL,Server,索引结构及其使用(一)_[SQL,Server教程]
Reading number is top 10 pictures
Discharge accidentally Actresses by the breast4
10 powerless things in life
Sora aoi possession of boudoir2
Summer is most suitable for young people to travel in China9
中国的十元人民币的秘密
From China fortress sora aoi2
关于提肛的健身效果
治疗多发性骨髓瘤的特效药,一万二一支
Sell the barbecue as says father du breul4
A man's favorite things10
Download software ranking
WebService在.NET中的实战应用教学视频 → 第1集
Boxer's Top ten classic battle10
虚拟机5.5.3版
Tram sex maniac 2 (H) rar bag2
Boxer's Top ten classic battle8
美女写真3
Unix video tutorial14
Unix video tutorial15
Unix video tutorial12
c#程序设计案例教程
delv published in(发表于) 2014/1/27 6:47:49 Edit(编辑)
ASP.NET与数据库相关技巧_[Asp.Net教程]

ASP.NET与数据库相关技巧_[Asp.Net教程]

ASP.NET与数据库相关技巧_[Asp.Net教程]

一、取得数据表 i 行 j 列的值



//建立并打开数据库连接

OleDbConnection conn=new OleDbConnection();

conn.ConnectionString=strConnectionString;//strConnectionString为数据库连接字符串

conn.Open();

string sql="select * from NewsClass order by ClassId desc";

string x;

DataSet ds=new DataSet();

OleDbDataAdapter da=new OleDbDataAdapter(sql,conn);

da.Fill(ds,"NewsTable");

DataTable dt=ds.Tables["NewsTable"];

x=dt.Rows[i][1].ToString()//数据表i行j列的值

conn.close();



二、将数据读入DropDownList


(1)DropDownList中添加数据



//建立并打开数据库连接

OleDbConnection conn=new OleDbConnection();

conn.ConnectionString=strConnectionString;//strConnectionString为数据库连接字符串

conn.Open();

string sql="select * from NewsClass order by ClassId desc";

//建立数据集

DataSet ds=new DataSet();

OleDbDataAdapter da=new OleDbDataAdapter(sql,conn);

da.Fill(ds,"NewsTable");

this.DropDownList1.DataSource=ds;

this.DropDownList1.DataTextField = "ClassName";//Text值

this.DropDownList1.DataValueField = "ClassID";//Value值

this.DropDownList1.DataBind();

conn.Close();



(2)选中DropDownList的某项



this.DropDownList1.Items.FindByValue(dr["ClassID"].ToString().Trim()).Selected=true;

//dr为DataRow



三、分类编码检索出相应的分类名称并在DataGrid中显示


(1).ASPX中的代码(ClassID为分类编码)







Text='<%# GetClassName(Convert.ToInt32(DataBinder.Eval(Container,

"DataItem.ClassID"))) %>'>








(2)C#代码



///



/// "分类"列根据数字返回文字

///

///

///

public string GetClassName(int ClassID)

{

OleDbConnection conn=new OleDbConnection();

conn.ConnectionString=strConnectionString;

conn.Open();

string sql="select * from NewsClass where ClassID="+ClassID;

DataSet ds=new DataSet();

OleDbDataAdapter da=new OleDbDataAdapter(sql,conn);

da.Fill(ds,"ClassTable");

DataTable dt=ds.Tables["ClassTable"];

string strClassName=dt.Rows[0]["ClassName"].ToString();

conn.Close();

return strClassName;//返回 ClassID对应的ClassName

}








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.