Problem with AddInParameter and Oracle in DAAB

Topics: Data Access Application Block
Jan 29, 2008 at 12:34 PM
I'm not sure why it's only parameters I always have trouble with in Oracle and DAAB. I guess it's why in the past I always avoid them and create the SQL INSERT statement by hand.

I'm trying to INSERT a record into an Oracle database using DAAB and I want to use parameters. I looked at some of the code David Hayden posted and came up with the following:

string sql = "INSERT INTO MyTable VALUES (:key, :year, :month)";
Database database = DatabaseFactory.CreateDatabase();
DbCommand command = database.GetSqlStringCommand(sql);

database.AddInParameter(command, "key", DbType.String, this.Key);
database.AddInParameter(command, "year", DbType.String, this.Year);
database.AddInParameter(command, "month", DbType.String, this.Month);

command.ExecuteNonQuery();

But when I run this I get "Operation is not valid due to the current state of the object." I would like to use parameters but I find myself wasting too much time trying to implement it. Is there something simple I'm missing? Does anybody have a complete example showing how this works?

Thanks a lot,
dave