In my previous post on c# operation SQLite, I found that sometimes the following errors occur when running:
SQLite error near “@table”: syntax error
The error code is as follows:
public static Tuple<bool, DataSet, string> GetBarcode(string barcode)
{
if (string.IsNullOrEmpty(barcode))
{
return new Tuple<bool, DataSet, string>(false, null, "The passed parameter cannot be empty");
}
string sql = "SELECT * FROM @table WHERE Barcode = @barcode";
SQLiteParameter[] parameter = new SQLiteParameter[]
{
new SQLiteParameter("table", "Database Table Name"),
new SQLiteParameter("barcode", barcode)
};
return SQLiteHelpers.ExecuteDataSet(sql, parameter);
}
Solution:
I found that the database table name cannot be added to the SQLiteParameter parameter list, the other column names are fine, and the SQL statement will not report an error if you change to the string connection method, as follows.
public static Tuple<bool, DataSet, string> GetBarcode(string barcode)
{
if (string.IsNullOrEmpty(barcode))
{
return new Tuple<bool, DataSet, string>(false, null, "The passed parameter cannot be empty");
}
string sql = string.Format("SELECT * FROM {0} WHERE Barcode = @barcode", "Database Table Name");
SQLiteParameter[] parameter = new SQLiteParameter[]
{
new SQLiteParameter("barcode", barcode)
};
return SQLiteHelpers.ExecuteDataSet(sql, parameter);
}
Read More:
- org/sqlite/native/Mac/aarch64 Error [How to Solve]
- [Solved] Laravel Create Data Table Error: Syntax error or access violation: 1071 Specified key was too long
- DataTables warning encountered using DataTables: table id = DataTables_Table_0 – Ajax error. For more information ab
- [Solved] pagehelper Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 1’
- How to Solve Doris dynamic partition table routineload Error
- Mybatis Error: Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect EQ
- Ant Design Vue-Table Error: warning.js?2149:7 [How to Solve]
- ‘pre-mature EOF‘ : syntax error syntax error [How to Solve]
- Laravel model save if the table has no ID field Error [How to Solve]
- Doris BrokerLoad Error: No source file in this table [How to Solve]
- Element table Error: ‘tableId‘ of undefined“ [How to Solve]
- [Solved] Ora-01652 Error: unable to extend temp section through 128 (in table space temp)
- The loop of life and death occurs when the El table component of element UI is bidirectional bound
- [Solved] Hbase …ERROR: Unable to read .tableinfo from file:/hbaseData/data/default/table1/xxxx
- [Solved] PhoenixParserException:ERROR 602 (42P00): Syntax error. Missing ‘EOF’
- ArcGIS error 999999: error executing function, table not found.
- How to Solve NCC2005 Error: get table metadata error
- [error record] Android application release package error handling (turn off syntax check log processing release configuration)
- Vue el-table Error: Duplicated keys detected This may casuse an update error
- [Solved] Failed update hbase:meta table descriptor HBase Startup Error