Manipulating the DBF database using C #

Source: Internet
Author: User
Tags odbc table name

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

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.