Passing Decimal to SQL Server with Data Adapter

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I'm using the following code to update my DataSet and
then update the datasource, a SQL Server 2000 database.
The code runs without throwing the error. However, when I
look at my SQL DB Table all of the decimals that I
attempted to pass into it have been stored as a 0. The
strings are passing fine.
Is there something that I'm missing? The SQL Table
has decimal(18,4). The variables are good as I'm using
them in calculations with no problem.
Can someone point me in the right direction? Thanks.

Try

Dim newRow As DataRow = DsPlate.TblPlate.NewRow
newRow("PlateNum") = txtPlateNum.Text
newRow("SubVal") = decSubVal
newRow("hbKitNum") = strHBKitNum
newRow("EXPKit") = strExpKit
newRow("ConKit") = strConKit
newRow("EXPCon") = strExpCon
newRow("NCal1") = decNCal1
newRow("NCal2") = decNCal2
newRow("NCal3") = decNCal3
newRow("PCACon") = decPCACon
newRow("PCBCon") = decPCBCon
newRow("PCATest") = decPCATest
newRow("PCBTest") = decPCBTest
newRow("ExNegConA") = decExNegConA
newRow("ExNegConB") = decExNegConB
newRow("ExPosConA") = decExPosConA
newRow("ExPosConB") = decExPosConB
newRow("ExPosTestA") = decExPosTestA
newRow("ExPosTestB") = decExPosTestB
newRow("Ncalx") = decNCalx
newRow("Cutoff") = decCutoff
newRow("Confirmed") = strPlateConfirm
DsPlate.TblPlate.Rows.Add(newRow)

SQLDA.Update(DsPlate, "TBLPlate")

Catch ex As Exception
MessageBox.Show("There has been an error
saving the data.", "Data Entry Error",
MessageBoxButtons.OK, _
MessageBoxIcon.Stop)

End Try
 
Mark,

Are you using a Strongly Typed Dataset? If so, then use
the NewtblPlateRow instead of NewRow. You will get the
schema for the row and it will preserve the decimal
places.

If you are not using a strongly typed dataset, then break
on the code and check your values in NewRow. They are
probably defaulting to string or int which might explain
the loss of data.

HTH,
Dennis
 
Back
Top