Stick to Learning asp.net--(22)

Source: Internet
Author: User
asp.net 3, write a database operation program below.

The contents of the table are as follows:

Http://www.machigroup.cn/machibbs/UploadFile/2004-8/2004826163932766.rar

Download and see what you can do.

Operation code: My virtual directory is built in the c:/aspnet, and the database is here.

<% @Import namespace= "System.Data"%>
<% @Import namespace= "System.Data.OleDb"%>
<script language= "C #" runat= "Server" >
void Page_Load ()
{
OleDbConnection objconnection;
OleDbDataAdapter objcommand;
String strconnect;
String strcommand;
DataSet dataset1=new DataSet ();

strconnect=@ "Provider=Microsoft.Jet.OLEDB.4.0;";
strconnect+=@ "Data source=c:\aspnet\machi.mdb;";
strconnect+=@ "Persist security Info=false";
Strcommand= "SELECT * from admin";
Objconnection=new OleDbConnection (StrConnect);
Objcommand=new OleDbDataAdapter (strcommand,objconnection);

Objcommand.fill (DataSet1, "admin");
datagrid1.datasource=dataset1.tables["Admin"]. DefaultView;
Datagrid1.databind ();
}
</script>
<body>

<asp:datagrid id= "DATAGRID1" runat= "Server"/>

</body>



The results of the operation are shown below:



4, we bind to an XML file below.

The source file for the XML is as follows 6.xml:



<?xml version= "1.0"?>
<gudenglangzi>
<wenji>
<names>liulangdejinw</names>
<url>http://oixq.126.com</url>
</wenji>
<wenji>
<names>xxx911</names>
<url>http://oixq.xxx.com</url>
</wenji>
<wenji>
<names>blog</names>
<url>http://blog.csdn.net/oixq</url>
</wenji>
</gudenglangzi>



The operating procedure is 6.aspx, the code is as follows:



<% @Page language= "C #"%>
<% @Import namespace= "System.Data"%>
<% @Import namespace= "System.Xml"%>
<script language= "C #" runat= "Server" >
void Page_Load ()
{

String xmlfilename=@ "C:\aspnet\6.xml";

DataSet newdataset1=new DataSet ();

Newdataset1.readxml (XMLfileName);
Datagrid1.datasource=newdataset1;
Datagrid1.databind ();
}
</script>
<body>

<asp:datagrid id= "DATAGRID1" runat= "Server"/>

</body>



The results of the run are as follows:







Here today, the code is written in WordPad test, beginners do not recommend the use of Microsoft's large system to compile software.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.