J
jh
I have a table defined as:
create table product_price
(
productId int,
price number(20,10),
price_date date,
primary key (productId)
);
I am reading through a price file in c# and I would like to insert a row
into the table for every price+date+productId combination. I am using
the DataAdapter insertCommand and Table.Rows.Add(newRow) method but it
fails when setting the date of the new row.
// Setting the insert command
priceDA.InsertCommand = priceDA.SelectCommand.Connection.CreateCommand
();
priceDA.InsertCommand.CommandText = "insert into product_price
(productId, price, price_date)" +
"values (@productId, @price, TO_DATE('@priceDate', 'YYYYMMDD'))";
// Adding the row
private void addPriceRow (int prodId, decimal price, DateTime priceDate,
DataTable priceTable)
// priceDate and other params defined elsewhere
DataRow newPriceRow = priceTable.NewRow();
newPriceRow["productId"] = prodId;
newPriceRow["price"] = prodPrice;
newPriceRow["price_date"] = priceDate;
priceDA.Update(priceDS, "product_price"); // Dies here with an oracle
error ORA-00936 missing expression
priceDS.AcceptChanges();
I think this is some sort of date format error, so I tried: newPriceRow
["price_date"] = priceDate.ToString("yyyyMMdd"); but that line fails at
runtime with: "String was not recognised as a valid DateTime"
Any ideas how I can save this date to the table?
Many thanks in advance.
create table product_price
(
productId int,
price number(20,10),
price_date date,
primary key (productId)
);
I am reading through a price file in c# and I would like to insert a row
into the table for every price+date+productId combination. I am using
the DataAdapter insertCommand and Table.Rows.Add(newRow) method but it
fails when setting the date of the new row.
// Setting the insert command
priceDA.InsertCommand = priceDA.SelectCommand.Connection.CreateCommand
();
priceDA.InsertCommand.CommandText = "insert into product_price
(productId, price, price_date)" +
"values (@productId, @price, TO_DATE('@priceDate', 'YYYYMMDD'))";
// Adding the row
private void addPriceRow (int prodId, decimal price, DateTime priceDate,
DataTable priceTable)
// priceDate and other params defined elsewhere
DataRow newPriceRow = priceTable.NewRow();
newPriceRow["productId"] = prodId;
newPriceRow["price"] = prodPrice;
newPriceRow["price_date"] = priceDate;
priceDA.Update(priceDS, "product_price"); // Dies here with an oracle
error ORA-00936 missing expression
priceDS.AcceptChanges();
I think this is some sort of date format error, so I tried: newPriceRow
["price_date"] = priceDate.ToString("yyyyMMdd"); but that line fails at
runtime with: "String was not recognised as a valid DateTime"
Any ideas how I can save this date to the table?
Many thanks in advance.