Connect to an Access database query statement

Source: Internet
Author: User

--Before using, be careful to change "configuration platform" of "Configuration Manager" in "Build" to X86

   Private voidButton1_Click (Objectsender, EventArgs e)//Enquiry{OleDbConnection conn=NewOleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\score.mdb; Jet oledb:database password=");//Connecting the Access2003 database stringOleDbCommand cmd =Conn.            CreateCommand (); Conn.            Open (); Cmd.commandtext="Select * FROM score"; OleDbDataReader Dr=cmd.            ExecuteReader (); DataTable DT=NewDataTable ();//Create a temporary table to store the data            if(Dr. HasRows) {//Adding Columns                                              for(inti =0; I < Dr. FieldCount; i++) {dt. Columns.Add (Dr. GetName (i));//Dr. GetName (i) Get column names} dt.                Rows.clear (); //Adding Rows                 while(Dr. Read ())//While the loop is the data of each row, as long as there is data in the database, it will be read one line at a time, each read a row to execute while{DataRow row=dt.                    NewRow ();  for(inti =0; I < Dr. FieldCount; i++)//for Loop loops is the data that determines the column after a row{Row[i]= Dr[i];//i is the index//MessageBox.Show (Dr[i]. ToString ());} dt.                Rows.Add (row); }} conn.            Close (); Datagridview1.datasource= DT;//Data Source}

、、、、、 below is how to create a table in an Access database

Connect to an Access database query statement

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.