国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET與數(shù)據(jù)庫相關(guān)技巧

2024-07-10 13:07:32
字體:
供稿:網(wǎng)友
國內(nèi)最大的酷站演示中心!

一、取得數(shù)據(jù)表 i 行 j 列的值   

     //建立并打開數(shù)據(jù)庫連接
    oledbconnection conn=new oledbconnection();
    conn.connectionstring=strconnectionstring;//strconnectionstring為數(shù)據(jù)庫連接字符串
    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()//數(shù)據(jù)表i行j列的值  
    conn.close();

二、將數(shù)據(jù)讀入dropdownlist

(1)  dropdownlist中添加數(shù)據(jù)

  //建立并打開數(shù)據(jù)庫連接
    oledbconnection conn=new oledbconnection();
    conn.connectionstring=strconnectionstring;//strconnectionstring為數(shù)據(jù)庫連接字符串
    conn.open();

    string sql="select * from newsclass order by classid desc";
    //建立數(shù)據(jù)集
    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

三、分類編碼檢索出相應(yīng)的分類名稱并在datagrid中顯示

(1).aspx中的代碼(classid為分類編碼):

    <asp:templatecolumn headertext="類 別">
         <itemtemplate>
          <asp:label id=lblclass runat="server" text='<%# getclassname(convert.toint32(databinder.eval(container, "dataitem.classid"))) %>'>
          </asp:label>
         </itemtemplate>
        </asp:templatecolumn>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 旌德县| 连州市| 平阳县| 赤壁市| 扶风县| 左贡县| 孝感市| 志丹县| 普安县| 新闻| 黑龙江省| 象州县| 潜山县| 东乌珠穆沁旗| 昌黎县| 瓦房店市| 德化县| 安吉县| 玛纳斯县| 西贡区| 志丹县| 深州市| 平果县| 富锦市| 长垣县| 横山县| 繁峙县| 凌云县| 左贡县| 赤壁市| 象州县| 德兴市| 红河县| 肃宁县| 乐陵市| 玉田县| 绥滨县| 加查县| 仁寿县| 称多县| 肃北|