2016-12-04 72 views
2

我试图在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(); 

personquotedate都是字符串和结构的数据库如下所示:

id = INTEGER PRIMARY KEYuser = STRING(255)quote = STRING(255)date = STRING(255)

+0

它看起来像你想插入一个字符串(在第一个元素插入数据值子句)转换为整数(id)。 –

+0

我不知道mismatch问题,但你可以写这样的查询太字符串stmt = string.Format(“INSERT INTO引号(用户,报价,日期)VALUES('{0}','{1}','{ 2}')“,person,quote,date);如果id是自动增加的。 –

+0

从使用SQL参数开始。如果文本包含“O'Toole”之类的东西,它会崩溃;他们也将确保通过正确的类型 – Plutonix

回答

2

如果ID是自动增量,你可以用这个查询

​​
+0

作品,谢谢.. – John

+0

你能接受答案,如果这对你有用。 –

+0

我会尽快让我 – John