Combination of Asp.net and Access Database

Source: Internet
Author: User

Combination of Asp.net and Access Database
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.
the latter is recommended. The former may be an absolute path, while the latter may be a relative path. Path, with a low chance of error.
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:
SQL server starts with SQL, such as sqlcommand cmd = new sqlcommand ();
access all starts 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. You can use the above connection statement
the connection is successful. Later, I thought it would be a bit safer, to set the password for opening the MDB file in the database, click
I will open the MDB file and set the password in "Tools",-"security"-"set Database Password, however,
then I couldn't connect to the database. I tried to add UID and PWD similar to sqlserver in the connection statement.
but it didn't succeed. Finally, I tried it, A solution is found:
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 the original one. You can connect to the data without making any changes. Library.

5> the access field type is difficult to match with oledbtype,
you can obtain the similar information, such as the remark type in access, and 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);

Related Article

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.