1. How to use Access
I used Access a little two years ago and felt that it had many small problems, so I didn't use it anymore. This time the program is placed on a gigabit wide network virtual host. This virtual host does not support Sqlite. It is good when reading data. As long as you write something into the database, an error will be reported. Some Disk I/O Error Obcured. It's amazing. I'll try it if I change to a virtual host, no problem. It means it is not a problem with my program. Later, it could only be changed to Access. It is actually similar to using read databases. It is mainly a problem of connecting strings, and some database differences should be paid attention to.
1.1 Database connection string
<add name="ConnectionString" connectionString="data source=|DataDirectory|\;Provider=.4.0" /> The connection string is very simple. You only need to specify the DataSource. Here |DataDirectory| refers to the App_Data directory. This method makes it convenient for us to specify the location of the database file using relative paths. The Provider here uses Oledb driver.
1.2 Use
It is very simple to use in a program, just replace the prefix before Connection and Command. To give an example:
public DataTable GetAll(string num,int min,int startRecord, int pageSize)
{
string sql = ("select Num ,minPrice ,isUsed from PhoneNumber where Num like '{0}%' and isUsed=0", num);
if (min != 0)
{
sql += "and minPrice=@p1";
}
using (OleDbConnection conn = new OleDbConnection())
{
();
OleDbCommand cmd = ();
= sql;
if (min != 0)
("p1", min);
OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
DataTable table = new DataTable();
(startRecord,pageSize,table);
return table;
}
}
Of course, you also need to add using: using;
The handling method of using ; is very similar. In fact, there is a set of Connection, Command and other classes prefixed with Db. These specific classes are inherited from DbConnection, so they all look the same.
1.3 Differences
As mentioned above, Access is very weird. Here are some of the things I encountered:
1.3.1 user is a keyword. If there is a table name or a column name is user without brackets, an error will occur. 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 cause 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# before inserting it.
1.3.3 There is no bool type, or bit type, called yesno...
1.3.4 Multiple SQL lines are not supported in one command. This limitation is also very annoying. Each time a command is executed, it can only contain one SQL, which is very inconvenient. Even a database like Sqlite does not have this limitation.
1.3.5 The issue of parameter order. The declared parameter order must be consistent with the declaration you add parameter to the command. Otherwise, it is very likely that no error will be reported, but the result will not be affected (I haven't tried it at other times when I update). Access is really a top-notch database! ! For example
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";
= sql;
("p1", );
("p3", );
("p4", );
("p5", );
("p6", );
("p7", );
("p8","");
("p9", ()?" ":);
("p10", ()?" ":);
("p2", );
int i= ();This is OK, but
("p2", );
It doesn't work if you mention it before, and it won't be updated. Fortunately, I found someone asking this question on csdn, otherwise I wouldn't know how to do it.
-index problem.
The z-index of the HTML element contained within other HTML elements is only relative to the z-index of the element located at the same level, and has no effect on the z-index of the element outside its parent element. That is to say, if the z-index of the parent element is very small, such as 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 coincides with the adjacent element, then the overwritten element is still the internal element.
I used Access a little two years ago and felt that it had many small problems, so I didn't use it anymore. This time the program is placed on a gigabit wide network virtual host. This virtual host does not support Sqlite. It is good when reading data. As long as you write something into the database, an error will be reported. Some Disk I/O Error Obcured. It's amazing. I'll try it if I change to a virtual host, no problem. It means it is not a problem with my program. Later, it could only be changed to Access. It is actually similar to using read databases. It is mainly a problem of connecting strings, and some database differences should be paid attention to.
1.1 Database connection string
<add name="ConnectionString" connectionString="data source=|DataDirectory|\;Provider=.4.0" /> The connection string is very simple. You only need to specify the DataSource. Here |DataDirectory| refers to the App_Data directory. This method makes it convenient for us to specify the location of the database file using relative paths. The Provider here uses Oledb driver.
1.2 Use
It is very simple to use in a program, just replace the prefix before Connection and Command. To give an example:
Copy the codeThe code is as follows:
public DataTable GetAll(string num,int min,int startRecord, int pageSize)
{
string sql = ("select Num ,minPrice ,isUsed from PhoneNumber where Num like '{0}%' and isUsed=0", num);
if (min != 0)
{
sql += "and minPrice=@p1";
}
using (OleDbConnection conn = new OleDbConnection())
{
();
OleDbCommand cmd = ();
= sql;
if (min != 0)
("p1", min);
OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
DataTable table = new DataTable();
(startRecord,pageSize,table);
return table;
}
}
Of course, you also need to add using: using;
The handling method of using ; is very similar. In fact, there is a set of Connection, Command and other classes prefixed with Db. These specific classes are inherited from DbConnection, so they all look the same.
1.3 Differences
As mentioned above, Access is very weird. Here are some of the things I encountered:
1.3.1 user is a keyword. If there is a table name or a column name is user without brackets, an error will occur. 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 cause 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# before inserting it.
1.3.3 There is no bool type, or bit type, called yesno...
1.3.4 Multiple SQL lines are not supported in one command. This limitation is also very annoying. Each time a command is executed, it can only contain one SQL, which is very inconvenient. Even a database like Sqlite does not have this limitation.
1.3.5 The issue of parameter order. The declared parameter order must be consistent with the declaration you add parameter to the command. Otherwise, it is very likely that no error will be reported, but the result will not be affected (I haven't tried it at other times when I update). Access is really a top-notch database! ! For example
Copy the codeThe 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";
= sql;
("p1", );
("p3", );
("p4", );
("p5", );
("p6", );
("p7", );
("p8","");
("p9", ()?" ":);
("p10", ()?" ":);
("p2", );
int i= ();This is OK, but
("p2", );
It doesn't work if you mention it before, and it won't be updated. Fortunately, I found someone asking this question on csdn, otherwise I wouldn't know how to do it.
-index problem.
The z-index of the HTML element contained within other HTML elements is only relative to the z-index of the element located at the same level, and has no effect on the z-index of the element outside its parent element. That is to say, if the z-index of the parent element is very small, such as 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 coincides with the adjacent element, then the overwritten element is still the internal element.