DataAdapter posts "0.0" to DB when Param contains System.DbNull

  • Thread starter Thread starter Tom Luetz II
  • Start date Start date
T

Tom Luetz II

I'm having some trouble with the DataAdapter in my code. When the parameter
in an OleDbCommand, which is created
as having a type of OleDbType.Decimal, is set to System.DbNull, the actual
value posted to the database upon execution of the Insert command is a
floating point value of zero (0.0, actually).

The DataAdapter is associated with a DataGrid. When a row is inserted into
the grid, the column may contain either nothing "(null)"
or a floating point value.

Here's some excerpts from the code that may help someone help me with this:

DAdapter = New OleDbDataAdapter

'Build insert command
CommandText = "Insert into db.threshold threshd_critical) values (?)"
DAdapter.InsertCommand = New OleDbCommand(CommandText, mConnection)

'Define parameters for insert command
workParam = DAdapter.InsertCommand.Parameters.Add("threshd_critical",
OleDbType.Decimal)
workParam.SourceColumn = "threshd_critical"
workParam.SourceVersion = DataRowVersion.Current

Any assistance would be greatly appreciated!

Tom
 
Hi Tom,

Several issues can exhibit this symptom. Would you please let me know what
database you're using (I'm assuming it's Microsoft Access, since you're
using OleDb), and we can narrow down the issue. This may not be an issue
with the DataAdapter (I assume you've tested this with a straight SQL
statement in your database's UI?).

HTH,
Derrick
 
The database being used is IBM UDB DB2 v7.2.

If you execute the SQL manually, the proper value is inserted into the
database.

I should have mentioned that my code worked just fine when the
InsertCommand's
parameter was defined as OleDbType.Integer; only when it was changed to
Decimal
did I start to have the aforementioned problem.

Thanks,
Tom
 
The database being used is IBM UDB DB2 v7.2.

If you execute the SQL manually, the proper value is inserted into the
database.

I should have mentioned that my code worked just fine when the
InsertCommand's
parameter was defined as OleDbType.Integer; only when it was changed to
Decimal
did I start to have the aforementioned problem.

Thanks,
Tom
 
Back
Top