asp.net入门来一遍----数据存取
protected dataset loadmypbdata()
{
string sourcexml = server.mappath("phone.xml");
dataset dataset = new dataset();
try
{
dataset.readxml(sourcexml);
}
catch (exception e)
{
dataset = null;
}
return dataset;
}
void page_load(object sender, eventargs e)
{
if (!(page.ispostback))
{
gridv.datasource = loadmypbdata();
gridv.databind();
}
}
-------------------------------
string strsql="data source=127.0.0.1;initial catalog=dotnet;persist security info=true;user id=sa;password=1234;packet size=4096";
sqlconnection myconn = new sqlconnection(strsql);
myconn.open();
string commsql = "select * from gbook order by id desc";
sqldataadapter adp = new sqldataadapter(commsql,myconn);
dataset ds = new dataset();
adp.fill(ds);
datagrid1.datasource = ds;
datagrid1.databind();
myconn.close();
---------------------------------------
if(!ispostback)
{
oledbconnection myconnection =new oledbconnection("provider=microsoft.jet.oledb.4.0;data source="+server.mappath("new.mdb"));
oledbdataadapter mycommand=new oledbdataadapter("select id,typename from bb ",myconnection);
dataset ds= new dataset();
mycommand.fill(ds,"bb");
dropdownlist2.datasource = ds.tables["bb"].defaultview;
dropdownlist2.datatextfield = "typename";
dropdownlist2.datavaluefield = "id";
dropdownlist2.databind();
上一篇: 专家解答夏至过后如何养生