Link to home
Start Free TrialLog in
Avatar of leds769
leds769

asked on

Update a dBase (.dbf) file with values from .csv file - C# -editted to change question

Hi guys,

I have a dbf file that contains the columns PCD and Round. I also have a csv file that has the columns postcode and round. What I want to do it update the dbf file, Round column, with the values from the csv file, roundcode column, where PCD = postcode.

Any ideas on how to go about this...?

Many thanks in advance
leds769

EDIT:
Ok, I have decided the way to do it is to loop through the lines of the CSV file and update the DBF file that way - in testing the update, the code below throws an error, can anyone help me with this?

thanks
            OpenFileDialog dlg = new OpenFileDialog();
            //dlg.Filter = ".dbf";
 
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string fileName = dlg.SafeFileName.Substring(0, dlg.SafeFileName.Length - 4);
                string filePath = System.IO.Path.GetDirectoryName(dlg.FileName);
                System.Data.Odbc.OdbcConnection connect;
                System.Data.Odbc.OdbcCommand cmd;
                connect = new System.Data.Odbc.OdbcConnection();
                connect.ConnectionString = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=" + filePath + ";";
                cmd = new System.Data.Odbc.OdbcCommand("UPDATE " + fileName + " AS F SET F.ROUNDCODE = 'test' WHERE F.POSTCODE = 'WV1 1AA';", connect);
                connect.Open();
                cmd.ExecuteNonQuery();
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leds769
leds769

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial