Now most C # connection databases will be SQL Server. However, the connection and operation of some old database files is not very familiar.
Today there is this problem, to the FoxPro generated DBF file database operation.
I have been on the csdn for a long time and most of the problems have not been well restored to these operational problems.
After my experiment, it's OK to connect it with ODBC.
The following is the code that is used.
is very simple, is the format to pay attention to. and the open query statement will be very different.
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 point:
1 format of the connection string.
The table name corresponding to 2 must have a path.
3 Windows 2003 operating system installed Vfpodbc.dll is 1.0 version, which will cause the connection is not, to replace the 6.1.8630.1 version, the server location C:\WINDOWS\system32, especially for multiple server clusters, Be sure to keep the same version when you deploy!
Http://www.cnblogs.com/tanjy/archive/2006/11/14/560046.html