In fact, the character connection string is very easy to write. It is mainly about getting this relative address. Now I will use the following methods:
Winfrom:
Write in the configuration file app. config
<Configuration>
<Connectionstrings>
<Add name = "access_conn
"Connectionstring =" provider = Microsoft. Jet. oledb.4.0; Data Source = | datadirectory |/ecard. MDB
"Providername =" system. Data. oledb "/>
</Connectionstrings>
</Configuration>
Note: To put ecard. MDB in the bin/debug folder, you must add a reference system. Configuration
Then write data in the database operation class
String conn = configurationmanager. connectionstrings ["access_conn
"]. Connectionstring;
Conn is the connection string ......
Asp.net:
First, write the following values in <etettings> of <configuration> in Web. config:
<Add key = "access_con
"Value =" provider = Microsoft. Jet. oledb.4.0; Data Source = "/>
<Add key = "access_path
"Value = "~ /App_data/xxedu. MDB
"/>
Then obtain the connection string when you want to perform database operations:
String strcon = configurationmanager. receivettings ["access_con
"]. Tostring () + httpcontext. Current. server. mappath (configurationmanager. deleettings [" access_path
"]) + ";";
Strcon is the database connection string.