c#操作DBF数据库

wsfyc009 2009-08-10 08:52:03
conn = new OdbcConnection();
filepath = System.IO.Directory.GetCurrentDirectory();
string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + filepath + ";Exclusive=yes;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=no";
conn.ConnectionString = connStr;
conn.Open();
string sql = @"select * from " + filepath + "\\WATER.dbf";
OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
System.Data.DataTable dtt = new System.Data.DataTable();
da.Fill(dtt);
DataRow row = dtt.NewRow();
row[0] = dt.Rows[i][0].ToString();
dtt.Rows.Add(row);
OdbcCommandBuilder en = new OdbcCommandBuilder(da);
da.Update(dtt); //这里更新出错,提示:file .dbf does not
但文件命名存在,不知道是什么原因啊
...全文
79 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigmingming 2009-08-10
  • 打赏
  • 举报
回复
  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();
   }
  注意点:1 连接串的格式。2 所对应的表名必须要有路径。
  http://www.cnblogs.com/tanjy/archive/2006/11/14/560046.html
wsfyc009 2009-08-10
  • 打赏
  • 举报
回复
自己解决。
string sql = @"select * from WATER.dbf";

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧