C # Reading DBF

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.