asp.net入门来一遍----数据存取

王朝asp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

因为正在设在设计一个asp.net+xml+delphi的三层设计

所以在对一简单的东西做了一下整理。

下面是对xml,access,mssql数据存取

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();

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有