【发布时间】:2025-12-31 12:25:11
【问题描述】:
我在我的访问数据库中插入一行时遇到问题。我不断收到“标准表达式中的数据类型不匹配”。我尝试了大量不同格式的查询,但似乎无法弄清楚我哪里出错了。
public void addUserToDB(string username)
{
string updateStr = "Insert Into Users ([Username], [Currency], [Joined], [Online], [Notes]) "
+ "Values ( ?, '0', ?, 'Yes', '')";
OleDbCommand update = new OleDbCommand(updateStr, con);
update.Parameters.Add("", OleDbType.VarChar).Value = username;
update.Parameters.AddWithValue("","'#" + DateTime.Now.ToString("G") + "#'");
update.Parameters.AddWithValue("","'#" + DateTime.Now.ToString("G") + "#'");
execute(update);
}
这不是我的连接字符串或其他任何东西,因为我的所有其他查询都可以正常工作。这里一定有什么东西。我假设可能与日期时间有关。
访问数据库:
用户名:ShortText
货币:数字
加入:“一般日期”格式的日期/时间
在线:是/否
备注:短文
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
好的,感谢您的意见和调整。
-
当您可以将字段默认为 Now() 并省去麻烦时,为什么还要插入一个日期呢?只有在运行更新查询时才使用日期。
标签: c# sql .net database ms-access