Reputation: 53
I´m having some issues inserting a float value in a DBF file from .NET. I use Visual Fox Pro OLEDB Driver for .NET and OleDbCommand to execute the query as follows
string sConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
System.Data.OleDb.OleDbConnection dbConn = new System.Data.OleDb.OleDbConnection(sConn);
OleDbCommand _insert = new OleDbCommand("INSERT INTO Table (string1,string2,float) values (?,?,?)", dbConn);
_insert.Parameters.Add("string1", OleDbType.Char).Value = "string1";
_insert.Parameters.Add("string2", OleDbType.Char).Value = "string2";
//here is the problem, this line doesn´t work, just insert a 0 valuein the field
_insert.Parameters.Add("float", OleDbType.Single).Value = float.parse("123");
//but instead, inserting value in floating point , field is updated
_insert.Parameters.Add("float", OleDbType.Single).Value = float.parse("1,3262473693533E-315");
I´ve tried all kind of conversions but none worked...anyone has an idea what is the correct way to insert float values in a DBF??
Thanks!
EDIT: i think i get to the point...i was using DBF plus viewer to open the DBF files and see the results, tried xBase View Database explorer and now i can see the correct values inserted...i guess DBF plus viewer has a problem with numeric values
Upvotes: 2
Views: 573
Reputation: 53
i just want to point out that in my code:
_insert.Parameters.Add("float", OleDbType.Single).Value = float.parse("123");
the value inserted is 0:
thanks for your help...
Upvotes: 0
Reputation: 4288
You may find this page on Visual FoxPro OLE DB Provider Data Support useful, it maps the OleDb types to Visual Foxpro types.
I created a DBF with a single float-type field of dimensions 10, 4 (so 4 decimal places) and using your code above it successfully inserts 123, 123.45 and so on from C# through OleDb.
OleDbConnection dbConn = new System.Data.OleDb.OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=c:\temp\numbertest.dbc");
OleDbCommand _insert = new OleDbCommand(@"INSERT INTO numbers (floatfield) values (?)", dbConn);
_insert.Parameters.Add("float", OleDbType.Single).Value = float.Parse("123.45");
dbConn.Open();
_insert.ExecuteNonQuery();
dbConn.Close();
So what are the type and dimensions of the target field in your own DBF file?
Upvotes: 2