PC Review


Reply
Thread Tools Rate Thread

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

 
 
Tom Luetz II
Guest
Posts: n/a
 
      24th May 2004
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


 
Reply With Quote
 
 
 
 
Derrick [MCSD]
Guest
Posts: n/a
 
      25th May 2004
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


"Tom Luetz II" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Tom Luetz II
Guest
Posts: n/a
 
      25th May 2004
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

"Derrick [MCSD]" <Derrick[underscore]Repep[at]toxicall[dot]com> wrote in
message news:%(E-Mail Removed)...
> 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
>
>
> "Tom Luetz II" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Tom Luetz II
Guest
Posts: n/a
 
      9th Jun 2004

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

> "Derrick [MCSD]" <Derrick[underscore]Repep[at]toxicall[dot]com> wrote in
> message news:%(E-Mail Removed)...
> > 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
> >
> >
> > "Tom Luetz II" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"'System.DBNull' is a 'type', which is not valid in the given context" - aka what type is DataRow column? mark4asp Microsoft ADO .NET 2 24th Sep 2007 05:03 PM
System.ArgumentException: Cannot set column "ColumnName" to be null. Please use DBNull instead. lgalumbres@gmail.com Microsoft VB .NET 0 30th Oct 2006 09:12 PM
Trying to filter an Access database with a Field LIKE "%" + "@PARAM" + "%" mosscliffe Microsoft ASP .NET 4 18th May 2006 10:13 PM
newsgroup keeps marking old "read" posts as "unread." Used2be Windows XP Help 3 7th May 2005 04:52 AM
Ted" <"""""""""" Is Back , Ignore his posts. Bob S Windows XP General 3 24th Jul 2003 11:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:30 AM.