When I completed the student management system, I found that to use this software, the database data source must be configured. So I want to get a version that is out of the data source.
Constructor:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/22345a634-0.jpg "title =" datafile.jpg "/>
If con1 connectionstring has a linked database file as the data source, we can use the database file to configure the data source.
So Baidu has a bit of Data Source = Data Source Path. The student data source has been registered in the registry. The student data source name is equivalent to the path.
Ideas:
Step 1: Get the absolute path of the database.
Step 2: Write ConnectionString in the Code. The Provider must write the driver name of the complete data Provider (for example
Provider = Microsoft. Jet. OleDb.4.0ACCESS data engine)
), While Data Source is written as an absolute path.
Key technologies:
1. Obtain the directory where the program is located and construct the absolute path:
SDBPath = extractFilepath (application. ExeName) + 'dataname. mdb ';
2. con1.ConnectionString: = 'provider = Microsoft. Jet. OLEDB.4.0; Data Source = '+ sDBPath + ';';
Steps:
I. There is such an Interface
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2234591315-1.jpg "title =" form.jpg "/>
2. Modify the con1 attributes first
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2234595593-2.jpg "title =" connect.jpg "/>
Modify attributes of adoquery
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2234592c4-3.jpg "title =" query.jpg "/>
In the form2 add onActivate event window to activate the event) the code is as follows,
Procedure TForm2.FormActivate (Sender: TObject); var sDBPath: string; begin sDBPath: = extractFilepath (application. exeName) + 'Students. mdb '; ADOQuery1.Active: = false; con1.Connected: = false; ADOQuery1. SQL. clear; ADOQuery1. SQL. add ('select * from admins'); // you can see whether the database is required to be created in the window and whether to write or not. // User ID = Admin; Add the corresponding username to the database // enter connectionstring con1.ConnectionString: = 'provider = Microsoft. jet. OLEDB.4.0; Data Source = '+ sDBPath +'; con1.Connected: = true; ADOQuery1.Active: = true; end;
In this way, the configuration of database disconnection from the data source is completed.
Sample Code http://pan.baidu.com/share/link? Consumer id = 187085761 & uk = 2065228996
This article is from the "lilin9105" blog, please be sure to keep this source http://7071976.blog.51cto.com/7061976/1220029