For the first time, I had some experience with others and wrote it down. Although it was a good dish, I still had to make some records. If there were any errors or omissions, please kindly advise. Thank you :)
Previously, we used Asp.net and sqlserver2000 to work together. This time we used access. Although it was the first time we used it, we felt that it was slightly different from sqlserver2000 in usage. The usage of the two was compared below:
Sqlserver2000:
1> namespace using system. Data;
Using system. Data. sqldb;
2> the connection statement is recorded in the previous document and is no longer recorded here.
Mainly records access usage:
1> namespace: using system. Data;
Using system. Data. oledb;
2> connection statement:
string constring = "provider = Microsoft. jet. oledb.4.0; Data Source = ";
constring + = server. mappath (@ "\ jlgps \ dB \ jlgps. mdb ");
// in the preceding statement," @ "indicates an absolute string, that is to say, "\" does not need to be expressed here as "\".
the first "\" indicates that it is from the root directory (for example, c: \ Inetpub \ wwwroot) find the "jlgps" directory. If "\"
is not added, it indicates that jlgps is located in the Program directory of the current application) find, then write @ "DB \ jlgps here. mdb.
it is recommended that the latter be used. The former may be an absolute path, while the latter may be a relative path, with a low chance of errors.
oledbconnection con = new oledbconnection (constring);
con. open (); // The database connection is complete.
3> command object:
the general usage is the same as that of sqlserver, but the name is slightly changed:
sqlserver starts with SQL, for example, sqlcommand cmd = new sqlcommand ();
and all access statements start with oledb, such as oledbcommand and oledbdatareader .... and so on
4> Questions about the user name and password of the Access Database:
the user name and password are not set in my access MDB file, the above connection statement can be used
the connection is successful. Later, I want to set the password for opening the MDB file in the database for a bit of security. On
I opened the MDB file, the password is set in "tool",-"security"-"set Database Password", but
the database cannot be connected, I tried to add UID and PWD in SQL Server in the connection statement.
however, I did not succeed. After some attempts, I found a solution to the problem:
do not set a password in "Tools",-"security"-"set Database Password", but in "Tools ", -"security"-
"user and group account", you can set a password to enable the password when opening the MDB File
, the database connection statement is still original. You can connect to the database without making any changes.
5> the access field type is incorrect. The access field type and oledbtype are difficult to match one by one.
You can obtain similar values, such as the remarks type in access, use
longvarchar in oledbtype. For example:
oledbparameter para = new oledbparameter ("@ profun", oledbtype. longvarchar);
para. value = myaddpro. profun; // a feature description parameter of a product object, remarks
cmd. parameters. add (para);