日期:2009-01-10  浏览次数:20414 次

因为正在设在设计一个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();