我正在使用这个查询将日期插入到表中:
DateTime dt = DateTime.Now;
String query = "Insert into \"Table1\" (\"tableDate\") values (:date1)";
NpgsqlConnection conn = new NpgsqlConnection(conex.getConnection());
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
NpgsqlParameter param = new NpgsqlParameter(":date1",NpgsqlTypes.NpgsqlDbType.Date);
param.Value = dt.ToShortDateString();
cmd.Parameters.Add(param); // <----------Here i get the error
cmd.ExecuteNonQuery();
conn.Close();
我现在可以插入表格中的任何其他值,所以问题一定是日期格式或其他什么错误,但我找不到答案。