0

My goal is to take a datagridview and save it to a .dbf file. Actually, I want to overwrite the existing contents of the .dbf file.

I thought that perhaps I would need to convert the datagridview into a datatable to make the OleDbConnection happy, so I did. However, when the program hits .Open(), I get OleDbException: Invalid Path or File name.

Can I even use a datatable as the Data Source, or does it have to be an actual directory or file?

Source:

di.filename = Path.Combine(ClsGlobalVar.GWritePath, path2: $"{di.dbf_name.Trim()}.dbf");
FileInfo fi = new FileInfo(di.filename);

DataTable dt_save = dataGridView1.DataSource as DataTable;

using (OleDbConnection dbf_connection = new OleDbConnection($@"Provider=VFPOLEDB.1; Data Source={ dt_save }"))
{
    dbf_connection.Open();
Igor
  • 60,821
  • 10
  • 100
  • 175
  • 1
    Place a break point on the 2nd to the last line where you create the new connection instance. Now evaluate `$@"Provider=VFPOLEDB.1; Data Source={ dt_save }"`, what is the value that is shown? Does that value make sense and do you think that you could pass that on a a parameter of connection constructor? – Igor Mar 06 '19 at 15:01
  • @Igor when i step through, I can click the magnifying glass on dt_save, and I see my datagridview there in the Data Set Visualizer. So, in my mind, it seems like it should work. I'm probably wrong though, correct? – blindfire_bandit Mar 06 '19 at 15:36

0 Answers0