This time in C # programming, the first time you use an Access database, focus on the time type, integer type. Whether the type ....; Having encountered a lot of difficulties, I put them down and share them with you.
One, the basic format of INSERT statement:
INSERT into tablename[(Column1name,[column2name, ...]) VALUES (value1, [value2, ...])
1. The field name of the table may be a reserved word for the database , in which case the field name should be enclosed in "[]".
Case of reserved words: INSERT into Employee ([Name],id,dno] VALUES (' Wang Qiang ', 4007, 3)
Non-reserved words: INSERT into Employee (name,id,dno) VALUES (' Wang Qiang ', 4007, 3)
Here, name is the keyword of the database, and name is not. So when you write the data, you have to avoid the reserved word.
2.INSERT into Persons VALUES (' Gates ', ' Bill ', ' xuanwumen ', ' Beijing ', 4007) here to note when using a string (text), add (') to the comment, To add the escape character to the programming language \ '
If it is an integer, do not use quotation marks, note that field names do not need to be quoted.
The following is the last SQL statement
String sql = "INSERT into Test ([datetime],rawinformation) VALUES (\ '" + dt. ToString () + "\ ', \ '" + raw + "\ ')";
Second, the basic format of the UPDATE statement
UPDATE Tablename SET column1name = value1,[column2name = value2, ...] [WHERE conditions]
1. When selecting or updating the where structure in SQL statements comparison of datetime
The final Solution execution string is two cases:
1.1string sql = "UPDATE [Test] SET [isinvaild]= \ '" + issuccess + "\", [silk]= "+ data[0] +", [zone1]= "+ data[1] +", [zone 2]= "+ data[2] +", [zone3]= "+ data[3] +", [zone4]= "+ data[4] +" where [datetime]=# "+ dt +" # "; 2.string sql = "UPDATE [Test] SET [isinvaild]= \ '" + issuccess + "\", [silk]= "+ data[0] +", [zone1]= "+ data[1] +", [zone2 ]= "+ data[2] +", [zone3]= "+ data[3] +", [zone4]= "+ data[4] +" where CStr (DateTime) =\ ' "+ dt+" \ "" |
Here are the main here:
The first case: the time format for the Access database needs to be labeled with a "#" number, and the second is DateTime or [] to label it.
Second case: We have converted the records in the field DateTime to the form of a string compared to the time selected
III. Basic format of the SELECT statement
SELECT column_name, [column_name,] ... From Table_list/view_list
Or in the selection of time to encounter the choice of problems encountered, compared to the final Solution
Common operations statements for Access databases in C # ... An error prone place