Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've used the ODBC driver when generating DataSets in Visual Studio 2010 multiple times, but this time it all went wrong. The table in the DB has a set of columns defined as numeric(7,2). I try to insert data through the autogenerated Insert method like this:
C#
int x = tableAdapterMyDataTable.Insert(
    (decimal)data.X,
    (decimal)data.Y,
    (decimal)data.Z);

In run-time I get an error saying:
ERROR [22P02] ERROR: invalid input syntax for type numeric: "-1,6"; Error while executing the query

Clearly it is a problem with the decimal separator being ',' (comma). Since there are no CultureInfo in the TableAdapter, I have trouble changing it. A useless workaround is to change the decimal symbol in Windows. That works, but can't be used.

Setting the culture of the application doesn't work either:
C#
Application.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag("en-US");


Any suggestions?

ODBC Driver 8.04
PostgreSQL 8.4
Posted
Updated 16-Jan-12 22:08pm
v2

1 solution

Lol, things work in mysterious ways!

It turns out that to get the Postgres ODBC driver to work properly I had to read from the table before inserting data into it. In all other applications I did read from the DB as well as write. In my current application I only write, and that was the difference.

So before I write, I have to do a little reading:
C#
someDataSetTableAdapters.amunds_dataTableAdapter taData =
    new someDataSetTableAdapters.amunds_dataTableAdapter();
someDataSet sds = new someDataSet();
someDataSet.amunds_dataDataTable adt = sds.amunds_data;
    
taData.Fill1(adt); // SELECT * FROM amunds_data LIMIT 1
int x = taWeatherData.Insert(
    (decimal)data.X,
    (decimal)data.Y,
    (decimal)data.Z);


Man, I've googled this one! Hope it will help somebody sometime in the future.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900