C#对DBF文件的操作

 1 protected void Page_Load(object sender, EventArgs e)  
 2     {  
 3         System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();  
 4         string table = @"D:\aaa\code.dbf";  
 5         string connStr=@"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + table + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO";  
 6   
 7         conn.ConnectionString = connStr;  
 8         conn.Open();  
 9          
10   
11         OdbcCommand cmd = new OdbcCommand();  
12         cmd.Connection = conn;  
13         string sql = "update " + table + " set other='2',rate=1.014 ";  
14         cmd.CommandText = sql;  
15         cmd.CommandType = CommandType.Text;  
16         cmd.ExecuteNonQuery();  
17   
18          sql = @"select * from " + table;  
19         OdbcDataAdapter da = new OdbcDataAdapter(sql,conn);  
20         DataTable dt = new DataTable();  
21         da.Fill(dt);  
22         this.GridView1.DataSource = dt.DefaultView;  
23         this.GridView1.DataBind();  
24     }  
25 
26 注意点:1 连接串的格式。2 所对应的表名必须要有路径

 

你可能感兴趣的:(C#对DBF文件的操作)