Http://blog.sina.com.cn/s/blog_54b576bb0100anku.html
Frequently used when using ACCESS DATA
String strsql = "insert table_name (col1, col2,..., coln) values (@ col1, @ col2,..., @ coln )";
To insert data into the database, the writing is actually faulty, refer to msdn, should be changed
String strsql = "insert table_name (col1, col2,..., coln) values (?,?,...,?) ";
Explanations from msdn:
IfCommandtypeSetText, Provided by ole db. netProgramParameters cannot be passedOledbcommandThe name of the called SQL statement or stored procedure. In this case, the question mark (?) must be used (?) Placeholder. For example:
Select * from MERs where customerid =?
Therefore,OledbparametercollectionThe order must correspond directly to the position of the question mark placeholder of the parameter.
Use of the parameter placeholder of SQL in. net
In general
- The ole db. NET Framework data provider and ODBC. NET Framework data provider do not support the named parameters used to pass parameters to SQL statements or stored procedures. In this case,Question mark (?) is required (?) Placeholder,The sequence must match the parameter sequence defined in the stored procedure,See the following example. Select * from MERs where customerid = ?; In access, you can use @ customerid or "?" But in DB2, you can only use "?", If you use the former, an error message is displayed.
The general rules are as follows:
- Sqlcommand shoshould be '@ 'character
- Oledbcommand or odbccommand shocould be '? 'Character
- Oraclecommand shoshould be ': 'character