日付列を持つ PostgreSQL テーブルに行を挿入しようとしています。UI では、ユーザーが適切な日付を選択する DateTimePicker を取得しました。これまでのところ、私はこれを得ました:
UI で:
objPresupuesto.date = this.dtpFechaPres.Value.ToString("yyyy-MM-dd");
行を挿入するメソッド:
NpgsqlCommand query = new NpgsqlCommand("insert into presupuesto(presupuesto, codigo, descripcion, fecha, cliente, proyecto, total) values(nextval('presupuesto_presupuesto_seq'), @codigo, @descripcion, @fecha, @cliente, @proyecto, @total);Select lastval();", conn);
...
query.Parameters.Add(new NpgsqlParameter("fecha", NpgsqlDbType.Date, 0, "fecha"));
...
query.Parameters[2].Value = obj.date.toString;//without the toString it also fails
次の例外がスローされます。
Specified cast is not valid.
obj.date 値は 2011-04-29 です。一重引用符で囲んでみましたが、これも失敗します。
データベースの列の型は日付です。
誰もこれを以前にやったことがありますか?何か案は?
このリンクを検索して確認しましたが、役に立ちませんでした。ありがとう