Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

Update problem with decimal value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andre Botelho - 09 Jan 2006 10:45 GMT
Hi there...

I am trying to update a dataset with a decimal value (precision 9,
scale 4).

This is the column in the XML file generated by the DataSet
<PERC_DESCONTO>23.0402</PERC_DESCONTO>

As you can see the value is 23.0402 but when I update this dataset the
exception "Parameter value '230402,0000' is out of range." is raised.
If I change the value to 23.04 it works fine. I am using
SqlCommandBuilder with SqlDataAdapter.

This is the code of the update method:

private bool UpdateDataSet(string TableName, DataSet dsUpdate,
SqlConnection Connection)
{
  try
  {
    Connection.Open();
    try
    {
      string CommandText = "SELECT * FROM " + TableName;
      SqlDataAdapter Adapter = new SqlDataAdapter(CommandText,
Connection);
      SqlCommandBuilder Builder = new SqlCommandBuilder(Adapter);

       Adapter.RowUpdated += new
SqlRowUpdatedEventHandler(OnRowUpdated);
       Adapter.Update(dsUpdate.Tables[0]);

        return true;
    }
    finally
    {
       Connection.Close();
    }
  }
  catch (Exception ex)
  {
      ErrorList.Append(ex.Message + Environment.NewLine +
ex.GetType().FullName);
      return false;
  }
}

Is this something about using commandbuilder? Maybe it's default scale
value is 2.
Thanks in advance for those who can  help me...

Sorry for the poor english.
Miha Markic [MVP C#] - 09 Jan 2006 11:44 GMT
Hi Andre,

You are certainly experiencing digital separator issue.
You are using , while elsewhere is used .
Hard to say where since you are not providing much code (where do you assign
parameter value, etc.)

Signature

Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

> Hi there...
>
[quoted text clipped - 48 lines]
>
> Sorry for the poor english.
Andre Botelho - 09 Jan 2006 12:14 GMT
Thanks Miha!!! That exactly my problem, I should have guessed it before.

Let me explain a little bit more about my project. It will read data
from a database, create a XML file and send it by FTP. Later the system
will download the XML and update data into another database.

To create the XML I use DataSet.WriteXML, after dowload to read it I use
DataSet.ReadXML. I parse the dataset and make some necessary updates. I
am testing this application right now and I am writing and reading the
XML in the same machine, so using the same regional settings. I thought
ADO.NET would follow my regional configuration, but as I could see now
it doesn't, no problem about that, but how can I set the decimal
separator during the SqlDataAdapter.Update method? Can I use it with
SqlCommandBuider or should I create the SqlCommands myself?

Thanks a lot for the help!

Andre Botelho

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Andre Botelho - 09 Jan 2006 13:09 GMT
Hi Miha... it's me again...

I've tried the following code:

CultureInfo myCI = new CultureInfo("es-ES", false);
myCI.NumberFormat.NumberGroupSeparator = ".";
myCI.NumberFormat.NumberDecimalSeparator = ",";
System.Threading.Thread.CurrentThread.CurrentCulture = myCI;

I did it before reading the source DataSet. Even changing the regional
settings the error remains the same. I am still making researchs on the
web... I thought it would be easier to solve...

see you...

Andre Botelho

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Marina - 09 Jan 2006 15:56 GMT
After you read the data in, and you check in your dataset, is the value
correct? Is the column a numeric column in the dataset? I am wondering if
this is an issue with the machine you are running your application on, or on
the database server (which can have its own regional settings).

> Hi Miha... it's me again...
>
[quoted text clipped - 16 lines]
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com 
Cor Ligthert [MVP] - 09 Jan 2006 16:19 GMT
Marina,

This is a strange problem. My settings are Dutch which have almost
completely the same behaviour as the Spanish even the currency sign.

This code (I had VB test project open and was to lazy to start a new C#
project)
\\\
Dim dt As New DataTable("Marina")
dt.Columns.Add("DecimalTest", GetType(System.Decimal))
dt.LoadDataRow(New Object() {23.0402}, True)
dt.WriteXml("c:\test1\marina.xml")
///
Creates this XML file
\\\
<?xml version="1.0" standalone="yes" ?>
- <DocumentElement>
- <Marina>
 <DecimalTest>23.0402</DecimalTest>
</Marina>
</DocumentElement>
///

In an XML file and in a SQLserver the decimal seperator is just a dot.
(with a toString it is represented with a comma for me 23,0402)

The region settings are AFAIK not important.

Cor
Cor Ligthert [MVP] - 09 Jan 2006 16:46 GMT
Doh,

The dot is of course not in SQL Server in that it are just value types in
which the decimal pointer is integrated.

Cor
Andre Botelho - 09 Jan 2006 16:30 GMT
Hi Marina...

I have just solved the problem some hours ago... it was exactly what
Miha told. The digital separator in the XML file is "." but my machine
is configured for ",".

In my previous post I said that I was trying to change the regional
configuration and it was not working, my failure, it does work.

I use the following code before parsing the DataSet and apply the
changes I want:

CultureInfo myCI = new CultureInfo("en-US", false);
myCI.NumberFormat.NumberGroupSeparator = ",";
myCI.NumberFormat.NumberDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture = myCI;

Now it is working fine... it is reading the value 23.0402 as 23,0402
instead of 230402,0000.

Thank you all for the help. I hope this issue will be usefull for others
in the future.

bye,

Andre Botelho

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Miha Markic [MVP C#] - 09 Jan 2006 19:19 GMT
Hi Andre,

You might also want to use CultureInfo.InvariantCulture (instead of setting
the separators yourself) which is sort of independent one.

Signature

Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

> Hi Marina...
>
[quoted text clipped - 26 lines]
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com 
Andre Botelho - 10 Jan 2006 13:25 GMT
Thanks for this tip Miha!

Andre Botelho

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.