Access usage Summary

Source: Internet
Author: User

1. How to Use Access
I used a little access two years ago. I feel that it is a lot of small problems and it will not be used again. This time Program It is placed on a virtual host with a gigabit network. This virtual host does not support SQLite. It is good to read data. If you write something into the database, an error will be reported, some disk I/O error occured. It's amazing. Try another VM. No problem. It is not a problem with my program. Later, only access is allowed. Reading databases using ADO. NET is similar, mainly because of the connection string problem. Note that there are some database differences.

1.1 database connection string

<Add name = "connectionstring" connectionstring = "Data Source = | datadirectory | \ We. MDB; provider = Microsoft. jet. oledb.4.0 "/> the connection string is simple. You only need to specify datasource. Here | datadirectory | refers to the app_data directory. This method of Asp.net makes it easy to use relative paths to specify the location of database files. The provider here adopts the oledb driver.

1.2 use

it is very easy to use in a program. You only need to replace the prefix before connection and command. For example: copy Code the code is as follows: public datatable getall (string num, int min, int startrecord, int pagesize)
{< br> string SQL = string. format ("select num, minprice, isused from phonenumber where num like '{0} %' and isused = 0", num);
If (Min! = 0)
{< br> SQL + = "and minprice = @ p1";
}< br> using (oledbconnection conn = new oledbconnection (sqlhelper. connstr)
{< br> Conn. open ();
oledbcommand cmd = Conn. createcommand ();
cmd. commandtext = SQL;
If (Min! = 0)
cmd. parameters. addwithvalue ("p1", min);
oledbdataadapter ADP = new oledbdataadapter (CMD);
datatable table = new datatable ();
ADP. fill (startrecord, pagesize, table);
return table;
}< BR >}

Add using: using system. Data. oledb;
Using system. data; ADO. net processing method is very similar, in fact, ADO. net has a set of connection, command, and other classes prefixed with DB. These classes are inherited from dbconnection, so they all look the same.

1.3 differences

As mentioned above, access is very strange. The following are some of my experiences:

1.3.1 user is a keyword. If the table name or column name is user without brackets, an error occurs. Of course, it is a good programming habit to consistently add brackets to all table names and column names.

1.3.2 directly inserting datetime type data will result in an error. Even if the field type in the database is indeed date, the insertion method is to insert the datetime type tostring () of C.

1.3.3 no bool type, or bit type, called yesno ......

1.3.4 Multiple SQL statements are not supported in a command. This restriction is also annoying. Each time you execute a command, it can contain only one SQL statement, which is very inconvenient. Even a database such as SQLite does not have this restriction.

1.3.5 Parameter order problems. the declared Parameter order must be the same as the parameter declaration you add to the command. otherwise, it is very likely that no error will be reported, that is, the results will not be affected (during the update process, I did not try it in other cases ). access is the best database !! For example Copy code The Code is as follows: String SQL = "Update [user] Set workfield = @ P1, Company = @ P3, Ic = @ P4, contact = @ P5, phone = @ P6, mobile = @ P7, address = @ P8, email = @ P9, Introduction = @ P10"
+ "Where username = @ p2 ";
Cmd. commandtext = SQL;
Cmd. Parameters. addwithvalue ("p1", entity. workfield );
Cmd. Parameters. addwithvalue ("P3", entity. Company );
Cmd. Parameters. addwithvalue ("P4", entity. Ic );
Cmd. Parameters. addwithvalue ("P5", entity. Contact );
Cmd. Parameters. addwithvalue ("P6", entity. Phone );
Cmd. Parameters. addwithvalue ("P7", entity. Mobile );
Cmd. Parameters. addwithvalue ("P8 ","");
Cmd. Parameters. addwithvalue ("P9", String. isnullorempty (entity. Email )? "": Entity. Email );
Cmd. Parameters. addwithvalue ("P10", String. isnullorempty (entity. Introduction )? "": Entity. Introduction );
Cmd. Parameters. addwithvalue ("p2", entity. username );
Int I = cmd. executenonquery ();

Cmd. Parameters. addwithvalue ("p2", entity. username );

As mentioned above, it won't work, and it won't be updated. Fortunately, someone found this problem on csdn, or they don't know how to do it.

2. Z-index problems.
The Z-index of the HTML element contained in other HTML elements is only relative to the Z-index of the element at the same level. It does not affect the Z-index of the element other than its parent element, that is to say, if the Z-index of the parent element is very small, for example, 0, the Z-index of the internal element is very high, 1000. the Z-index of the adjacent element of the parent element is 2. If the internal element overflows and overlaps with the adjacent element, the overwritten element is the internal element.

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.