Asp.net Access database connection string summary

Source: Internet
Author: User
Tags access database

Asp tutorial. net access database tutorial connection string summary

1. access database connection string. Configure the access file in the web. config file.

<Add key = "conn" value = "provider = microsoft. jet. oledb.4.0; data source ="/>
<Add key = "source" value = "app_databbs.mdb"/>

String constring = configurationmanager. apps tutorial ettings ["conn"] + httpcontext. current. server. mappath ("~ ") + Configurationmanager. Receivettings [" source "];

2. The access database is sensitive to keywords. For keywords such as password, brackets must be added for query. Otherwise, an error is returned.

String querystring = "insert into users ([username], [password], [gendor], [createtime]) values (@ username, @ password, @ gendor, @ createtime )";

3. For date fields, convert them to strings and then to dates.

Oledbparameter par = new oledbparameter ("@ createtime", convert. todatetime (userinfo. createtime. tostring ());

4. access database parameters are strictly ordered. If the order of parameters is incorrect, no error is reported during execution, but no insert or update operations are performed, which will not affect the database.

String updatestring = "update users set [username] = @ username, [password] = @ password, [gendor] = @ gendor where [id] = @ id ";
Oledbparameter [] pars = {
New oledbparameter ("@ username", userinfo. username ),
New oledbparameter ("@ password", userinfo. password ),
New oledbparameter ("@ gendor", userinfo. gendor ),
New oledbparameter ("@ id", userinfo. id)}; // If you write the id parameter before it, the execution will not succeed.

 

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.