Ok, here is my scenario, I have an asp web app that i'm converting to .net.
The app reads files and loads the data into SQL db, now, in my file it has
numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
files into the db and I run query analyzer I see the numbers as they are in
the file, but when I upload the same file in my .net version of the app, I
see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
69.0000001. The columns are defined as floats in the table, and I changed th
e
types in the code from float to double and even tried decimal, but no luck,
any suggestions on how to get the numbers to show correctly from my .NET app
when I run query anaylzer?how are you going from the text file to code to the database?
are you using xxx.Parse() (like float.Parse()) on a string or something...
Karl
http://www.openmymind.net/
http://www.fuelindustries.com/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
> Ok, here is my scenario, I have an asp web app that i'm converting to
> .net.
> The app reads files and loads the data into SQL db, now, in my file it has
> numbers like, 125.25, 3363.33, 69.00, and when the asp version uploads the
> files into the db and I run query analyzer I see the numbers as they are
> in
> the file, but when I upload the same file in my .net version of the app, I
> see the numbers like this in query anaylzer: 125.25636363, 3363.3320001,
> 69.0000001. The columns are defined as floats in the table, and I changed
> the
> types in the code from float to double and even tried decimal, but no
> luck,
> any suggestions on how to get the numbers to show correctly from my .NET
> app
> when I run query anaylzer?
>
the code isn't doing float.parse(), i picked the app up from a former
developer and trying to fix the mess left behind. He's reading the text
files, creating a datatable, then inserting that into the table. in the
datatable, he has something like this:
aColumn = new DataColumn(SALESAMOUNT, System.Type.GetType("System.Single"));
"Karl Seguin [MVP]" wrote:
> how are you going from the text file to code to the database?
> are you using xxx.Parse() (like float.Parse()) on a string or something..
.
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:55B4FFAE-4544-4937-9441-7648D4B6A929@.microsoft.com...
>
>
is he then doing somethng like
DataRow row = databable.NewRow();
row["SalesAmount"] = someValue;
or
row[12] = someValue;
?
if so, what type is someValue? a string?
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
> the code isn't doing float.parse(), i picked the app up from a former
> developer and trying to fix the mess left behind. He's reading the text
> files, creating a datatable, then inserting that into the table. in the
> datatable, he has something like this:
> aColumn = new DataColumn(SALESAMOUNT,
> System.Type.GetType("System.Single"));
>
> "Karl Seguin [MVP]" wrote:
>
like this:
DataRow row = databable.NewRow();
row["SalesAmount"] = arr[1].toString();
"Karl Seguin [MVP]" wrote:
> is he then doing somethng like
> DataRow row = databable.NewRow();
> row["SalesAmount"] = someValue;
> or
> row[12] = someValue;
> ?
> if so, what type is someValue? a string?
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:03221FAC-4874-4B25-89C4-0D163F91FF30@.microsoft.com...
>
>
well...so far everything looks ok...
can you put a breakpoint and see what format arr[1] is in. My guess is that
it's happening when the value is first loaded from the text file (perhaps
into arr[1]). Can you provide more chunks of code?
Karl
http://www.openmymind.net/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
> like this:
> DataRow row = databable.NewRow();
> row["SalesAmount"] = arr[1].toString();
>
> "Karl Seguin [MVP]" wrote:
>
I did that, and all the way through I can see the number being uploaded as
125.25, so could it be a SQL thing transforming the numbers or something I'm
missing?
"Karl Seguin [MVP]" wrote:
> well...so far everything looks ok...
> can you put a breakpoint and see what format arr[1] is in. My guess is tha
t
> it's happening when the value is first loaded from the text file (perhaps
> into arr[1]). Can you provide more chunks of code?
> Karl
> --
> http://www.openmymind.net/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:4D7E9908-E7A2-43EF-9495-9E643B23102B@.microsoft.com...
>
>
If the SQL column is a float, you might wanna try changing it to a decimal.
You'll also want to make sure your SqlCommand has a decimal type. Something
like:
command.CommandType = CommandType.Text;
command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
(@.SalesAmount)";
command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
command.Parameters[0].SourceColumn = "SalesAmount";
Karl
--
http://www.openmymind.net/
"CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>I did that, and all the way through I can see the number being uploaded as
> 125.25, so could it be a SQL thing transforming the numbers or something
> I'm
> missing?
>
> "Karl Seguin [MVP]" wrote:
>
I can't change the column in the db due to it "replication" to other tables,
etc. I did make it a decimal in the SQLCommand, but still no go. I can see
it in the table correctly via enterprise manager, but when i do a query via
Query analzer is where I'm seeing the incorrect number format.
"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u013J8xPGHA.3016@.tk2msftngp13.phx.gbl...
> If the SQL column is a float, you might wanna try changing it to a
> decimal. You'll also want to make sure your SqlCommand has a decimal type.
> Something like:
> command.CommandType = CommandType.Text;
> command.CommandText = "INSERT INTO SomeTable (SalesAmount) VALUES
> (@.SalesAmount)";
> command.Parameters.Add("@.SalesAmount", SqlDbType.Decimal);
> command.Parameters[0].SourceColumn = "SalesAmount";
>
> Karl
> --
> http://www.openmymind.net/
>
> "CsharpGuy" <CsharpGuy@.discussions.microsoft.com> wrote in message
> news:5EF97DBC-4C69-4B07-A484-9A95230A8208@.microsoft.com...
>
I don't think there's a good solution in that case. It would seem that the
person who designed the database might not have understood what Floats are.
Floating points are an approximate representation of your number - not all
values can't be represented. Decimals are used for exact numbers.
You might want to check out:
http://msdn.microsoft.com/library/d... />
3_6mht.asp
Karl
--
http://www.openmymind.net/
"CsharpGuy" <me@.me.com> wrote in message
news:e7jOI55PGHA.2108@.TK2MSFTNGP10.phx.gbl...
>I can't change the column in the db due to it "replication" to other
>tables, etc. I did make it a decimal in the SQLCommand, but still no go. I
>can see it in the table correctly via enterprise manager, but when i do a
>query via Query analzer is where I'm seeing the incorrect number format.
>
> "Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
> net> wrote in message news:u013J8xPGHA.3016@.tk2msftngp13.phx.gbl...
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment