Currently, most C # databases are connected to SQL server. However, I am not familiar with the connection and operations of some old database files.
This problem occurs today. You need to operate the DBF file database generated by FOXPRO.
I have been investigating CSDN for a long time, and most of the problems have not been well resolved to these operations.
After my experiment, you can use ODBC to connect to it.
The following code is used.
It is very simple, that is, pay attention to the format. It is very different from the open query statement.
Protected void Page_Load (object sender, EventArgs e)
{
System. Data. Odbc. OdbcConnection conn = new System. Data. Odbc. OdbcConnection ();
String table = @ "D: \ aaa \ code. dbf ";
String connStr = @ "Driver = {Microsoft Visual FoxPro Driver}; SourceType = DBF; SourceDB =" + table + "; Exclusive = No; NULL = NO; Collate = Machine; BACKGROUNDFETCH = NO; DELETED = NO ";
Conn. ConnectionString = connStr;
Conn. Open ();
OdbcCommand cmd = new OdbcCommand ();
Cmd. Connection = conn;
String SQL = "update" + table + "set other = '2', rate = 1.014 ";
Cmd. CommandText = SQL;
Cmd. CommandType = CommandType. Text;
Cmd. ExecuteNonQuery ();
SQL = @ "select * from" + table;
OdbcDataAdapter da = new OdbcDataAdapter (SQL, conn );
DataTable dt = new DataTable ();
Da. Fill (dt );
This. GridView1.DataSource = dt. DefaultView;
This. GridView1.DataBind ();
}
Note: the format of 1 connection string. The table name corresponding to 2 must have a path.