gpt4 book ai didi

c# - 尝试将数据插入 SQLite 数据库时数据类型不匹配

转载 作者:行者123 更新时间:2023-11-30 21:44:10 25 4
gpt4 key购买 nike

我试图在 C# 中将一条记录插入到一​​个表中,但是当我到达执行查询以将记录插入到表中的代码行时,它只是出现了这个错误:

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)

最佳答案

如果id是自增的,你可以用这个查询插入数据

stmt = string.Format("INSERT INTO quotes (user, quote, date) VALUES ('{0}', '{1}', '{2}')", person, quote, date);

关于c# - 尝试将数据插入 SQLite 数据库时数据类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40961589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com