Beginner's universal connection to access databases and various databases (original) in ASP.

Source: Internet
Author: User
Tags microsoft access database visual studio 2010

Previously engaged in the development of ASP, to the development of ASP, record the related operation process Memo.

Article I original, I am a novice, master please ignore, thank you!

Reason: Before using ASP to write a website, will use the Access database, online search ASP. NET Access database, the method is mostly with ADO or manually configured Web. config, took a lot of detours, Later found that the fact that the ASP has helped us do a good job, directly with it, this article in Visual Studio 2010, for example, lists all the steps.

First, the new website:

FILE--New--Website (shift+alt+n)

Visual C #--ASP.--Take a name (I took a articles here)

Second, before the database connection preparation:

Right-click on the articles below the solution and add-new folder (I'm named App_Data here)

Copy the new My.mdb file from Access to the App_Data folder, and drag the file directly into the App_Data folder of the interface.

If it is replicated in the file manager, it will have to be added again in the development environment. Method: Right-click on App_Data, add-Existing Item (SHIFT+ALT+A), find My.mdb, add

Third, connect the database (here is the Access database, the other is the same as the Excel method):

Server Explorer, right-click on the data connection, add connection

Data source Selection: Microsoft Access database file (OLE DB)

Database file name: Browse here, navigate to the My.mdb under the App_Data folder

Test the connection, no problem, just make sure.

Multiple database files to repeat the above steps, the system will automatically help you generate Web. config, the official publishing site, remember to manually change the server path correct

Iv. preparation of the database before use:

Right-click on the articles below the solution and add-new folder (I'm named Dal here)

Right-click on the DAL folder, add-new Item (Ctrl + shift+a)

Visual C #--Data--Datasets (I'm named Access.xsd here)--add

This will automatically open the Access.xsd file, the page is blank

Server Explorer, click the My.mdb in front of the data connection, expand the table, drag the table to the open Access.xsd interface, next, complete

* * Important *: Build, Build Solution (F6). This step must not be saved, otherwise the following steps the data source list is empty

Repeat the above steps for multiple database files

V. Start using the database:

Create a new ASPX page

From the data in the Toolbox, drag a ObjectDataSource to the editing interface, click the next >, select the data source, here should have just that table, select, Next, complete

Next, you can drag from the standard in the toolbox, such as CheckBoxList to the editing interface, click the next >, select the data column to bind

Next can also from the data in the Toolbox, drag a Repeater to the editing interface, click Next to the >, select the data source to bind, here should have just that table, select, Next, complete

Switch to source, add in middle of <asp:repeater ...></asp:repeater>: <itemtemplate><% #Eval (column name in table)%><br/> </ItemTemplate>

* * Note, first of all must drag a ObjectDataSource to the editing interface and select the data source, the following can be completely started free play.

Vi. Release:

Debug-Start Debugging (F5) You can see the results.

Summary

To do so, I feel that the net is very convenient, but the deeper things can not be seen, and even the basic knowledge of grammar is ignored (this can also be called developers?). ), looking at some of the data, found that ObjectDataSource is very powerful and can bind arbitrary data.

For example: Manually bind the data to the CheckBoxList control in Page_Load:

Checkboxlist1.datasource = new string[] {"AA", "BB", "CC", "DD"};
Checkboxlist1.databind ();

More knowledge of ASP is learning, I hope you do not laughed at.

Beginner's universal connection to access databases and various databases (original) in ASP.

Related Article

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.