国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 内江市| 额尔古纳市| 高碑店市| 甘德县| 从化市| 新竹市| 夏津县| 天水市| 平武县| 星座| 于田县| 洛川县| 峨眉山市| 美姑县| 巴林左旗| 石门县| 东台市| 嘉鱼县| 泾川县| 精河县| 普洱| 道真| 拜城县| 普宁市| 临武县| 类乌齐县| 龙江县| 高雄市| 阳信县| 定西市| 泰宁县| 乌拉特中旗| 玛沁县| 锡林郭勒盟| 瑞安市| 澄城县| 自贡市| 马公市| 宜州市| 巢湖市| 左云县|