一、取得数据表 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为分类编码):
<asp:templatecolumn headertext="类 别">
<itemtemplate>
<asp:label id=lblclass runat="server" text='<%# getclassname(convert.toint32(databinder.eval(container, "dataitem.classid"))) %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
新闻热点
疑难解答
图片精选