Many of the software we have developed need to interact with some old systems, and many of them are still Using FoxPro databases.. NET and sqlserver. The other day, I encountered a problem of reading the DBF data file to the datagridview datagriand then importing it to the sqlserver database. The difficulty was how to read the DBF file to the dataset or able. One of the following methods is to use the oledb class to read data. In some customers' computers, DBF components may not be read. here we need to install a file "vfpoledbsetup. msi ", this can be searched online, a bunch of, can also go to Microsoft official download. Code As follows:
String Filepath = Textbox2.text;// File path, for example, E: \ A. DBF
Fileinfo fi = New Fileinfo (filepath );
String Mulu = Fi. directoryname;
String Filename = Fi. Name;
Oledbconnection Conn= NewOledbconnection ();
StringTable=Filepath;
string connstr = @" provider = vfpoledb.1; data Source = " + mulu + " ; collating sequence = machine " ;
Conn. connectionstring=Connstr;
Conn. open ();
String SQL = @" Select * from " + Filename;
Oledbdataadapter da = New Oledbdataadapter (SQL, Conn );
Datatable dt = New Datatable ();
Da. Fill (DT );