我试图在C#中的表中插入一条记录,但是当我到达执行查询以将记录插入表中的查询时,它只是来到了这个错误:尝试将数据插入到SQLite数据库时数据类型不匹配
An exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll but was not handled in user code
Additional information: datatype mismatch
,我必须将数据插入到数据库的代码如下:
string stmt = string.Format("INSERT INTO quotes (id, user, quote, date) VALUES ('', '{0}', '{1}', '{2}')", person, quote, date);
SQLiteCommand cmd = new SQLiteCommand(stmt, connection);
int rowsAffected = cmd.ExecuteNonQuery();
person
,quote
和date
都是字符串和结构的数据库如下所示:
id = INTEGER PRIMARY KEY
,user = STRING(255)
,quote = STRING(255)
和date = STRING(255)
它看起来像你想插入一个字符串(在第一个元素插入数据值子句)转换为整数(id)。 –
我不知道mismatch问题,但你可以写这样的查询太字符串stmt = string.Format(“INSERT INTO引号(用户,报价,日期)VALUES('{0}','{1}','{ 2}')“,person,quote,date);如果id是自动增加的。 –
从使用SQL参数开始。如果文本包含“O'Toole”之类的东西,它会崩溃;他们也将确保通过正确的类型 – Plutonix