Browse database data in Excel

Source: Internet
Author: User

1. InVs2010Create a new"ExcelWorkbook project.

2. Select "Data/The "display data source" menu command opens the "Data Source" window.

3. Create a connection in the "Data Source" WindowSQL Server 2008Database data source, and select a data table.

4In the data source window, click a column name (for exampleName), A drop-down arrow is displayed on the right, click to display a list, select"Namedrange", And then drag the column to the worksheet.Sheet1OfA1Cell.

in this case, in the cell " A1 " creates a file named namenamedrange namedrange Control ( name is the column name, followed by namedrange is the suffix added by the system ). In addition, a studentbindingsource bindingsource (the data source table name and suffix bindingsource added by the System), a table adapter and a dataset instance added to this project (the content is located in sheet1.designer. CS medium ).

InSheet1.designer. CSFileBindtodataIn the functionNamenamedrangeControl boundBindingsourceThen the latter is boundDatasetInstance.

5. Repeat the previous step to add otherSheet1Drag the columns displayed in the table from the "Data Source" window to the corresponding cell (you must first define the columnsNamedrange).

6. Run at this time, inExcelOfSheet1You can see the databaseMydbMediumStudentA record in the table. To browse the records in the table, you also need to add some command buttons for navigation.

7. Drag from the public control4ButtonsSheet1Worksheet.

8InSheet1OfSheetaskstartupWrite the followingCode, Set4Button display text:

1 This . Button1.text = " | < " ;
2 This . Button2.text = " < " ;
3 This . Button3.text = " > " ;
4 This . Button4.text = " > | " ;

9. Double-clickButton1Click the event button to write the following code:StudentbindingsourceMove record:

 

1 Private Void Button#click ( Object Sender, eventargs E)
2 {
3 This . Studentbindingsource. movefirst ();
4 }

 

Similarly3The Code is as follows:

1 Private Void Button2_click ( Object Sender, eventargs E)
2 {
3 This . Studentbindingsource. moveprevious ();
4 }
5 Private Void Button3_click ( Object Sender, eventargs E)
6 {
7
8 This . Studentbindingsource. movenext ();
9 }
10 Private Void Button4_click ( Object Sender, eventargs E)
11 {
12 This . Studentbindingsource. movelast ();
13 }

10. Run the project and click4You can navigate between data records and view the data of different records in the worksheet.

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.