Brie
Brie

Reputation: 2359

SqlDataAdapter.Update truncates doubles to ints back in sql table

I am manipulating data in a DataTable, and then calling SqlDataAdapter.Update() to put the data back into the SQL DB. It mostly works - except I can see that right before I call Update(), the numbers in certain columns in the DataTable have decimal parts, but then after Update() I look in the SQL table and the fractional part of the number has been lopped off, and the values are all integers.

The original DataTable was created by SqlDataAdpater.Fill(), and SqlCommandBuilder was used to create the default Update/Insert/Delete commands. The select statement to fill the DataTable only consisted of one SQL table. The relevant SQL table column data type is decimal, and I confirmed that was the type of the column in the DataTable.

Any suggestions as to what I am missing here? Thanks for any assistance.

Upvotes: 0

Views: 229

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460108

As requested, my comment as answer:

Look at the DataAdapter's UpdateCommand's parameter-collection to see what Scale this field has. I assume it's 0 instead of 2 (your number of decimal places). Change it accordingly then.

Upvotes: 1

Related Questions