我公司常有的事情:
可以用Oledb或 ODBC驱动:
1:dbf文件可以用access打开;
2:在计算机上配置odbc数据源可以实现;

解决方案 »

  1.   

    例如:c:\a\a1.dbf
    这样写:
    string connString = "Provider=VFPOLEDB.1;Data Source=C:\\A";
    System.Data.OleDb.OleDbConnection odbcConn = new System.Data.OleDb.OleDbConnection( connString );
    然后其他和操作其他数据库一样!
      

  2.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.Odbc;namespace WindowsApplication95
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.DataGrid dataGrid1;
    private System.Windows.Forms.OpenFileDialog openFileDialog1;
    private System.Data.Odbc.OdbcDataAdapter odbcAd;
    private System.Data.Odbc.OdbcConnection odbcCon;
    private System.Data.Odbc.OdbcCommand odbcCom;
    private System.Windows.Forms.Button button3;
    DataSet ds=new DataSet();
    private System.Windows.Forms.ToolTip toolTip1;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.ComponentModel.IContainer components; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.dataGrid1 = new System.Windows.Forms.DataGrid();
    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
    this.button3 = new System.Windows.Forms.Button();
    this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
    this.groupBox1 = new System.Windows.Forms.GroupBox();
    this.groupBox2 = new System.Windows.Forms.GroupBox();
    ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
    this.groupBox1.SuspendLayout();
    this.groupBox2.SuspendLayout();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.button1.ForeColor = System.Drawing.SystemColors.ControlText;
    this.button1.Location = new System.Drawing.Point(272, 16);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(64, 24);
    this.button1.TabIndex = 1;
    this.button1.Text = "浏览";
    this.toolTip1.SetToolTip(this.button1, "点击此按钮,告诉程序DBF文件的位置");
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.button2.ForeColor = System.Drawing.SystemColors.ControlText;
    this.button2.Location = new System.Drawing.Point(8, 40);
    this.button2.Name = "button2";
    this.button2.Size = new System.Drawing.Size(88, 30);
    this.button2.TabIndex = 1;
    this.button2.Text = "提取新广告";
    this.toolTip1.SetToolTip(this.button2, "点击此按钮,将找到新的广告");
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // textBox1
    // 
    this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
    this.textBox1.BackColor = System.Drawing.Color.LemonChiffon;
    this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
    this.textBox1.ForeColor = System.Drawing.SystemColors.ControlText;
    this.textBox1.Location = new System.Drawing.Point(8, 16);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(248, 14);
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "";
    this.toolTip1.SetToolTip(this.textBox1, "您可以在这里输入DBF文件的名称(不包括后缀)");
    // 
    // dataGrid1
    //
      

  3.   

    this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
    this.dataGrid1.BackColor = System.Drawing.SystemColors.Info;
    this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Info;
    this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
    this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Info;
    this.dataGrid1.DataMember = "";
    this.dataGrid1.FlatMode = true;
    this.dataGrid1.HeaderBackColor = System.Drawing.SystemColors.ControlLight;
    this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
    this.dataGrid1.Location = new System.Drawing.Point(8, 24);
    this.dataGrid1.Name = "dataGrid1";
    this.dataGrid1.ParentRowsBackColor = System.Drawing.SystemColors.ControlText;
    this.dataGrid1.PreferredColumnWidth = 80;
    this.dataGrid1.ReadOnly = true;
    this.dataGrid1.RowHeadersVisible = false;
    this.dataGrid1.Size = new System.Drawing.Size(336, 192);
    this.dataGrid1.TabIndex = 3;
    this.toolTip1.SetToolTip(this.dataGrid1, "这里将显示找的新广告");
    // 
    // openFileDialog1
    // 
    this.openFileDialog1.Filter = "DBF文件 (*.dbf)|*.dbf|所有文件 (*.*)|*.*";
    this.openFileDialog1.InitialDirectory = "d:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\IDE\\dbfs";
    // 
    // button3
    // 
    this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.button3.ForeColor = System.Drawing.SystemColors.ControlText;
    this.button3.Location = new System.Drawing.Point(168, 40);
    this.button3.Name = "button3";
    this.button3.Size = new System.Drawing.Size(88, 30);
    this.button3.TabIndex = 4;
    this.button3.Text = "新广告入库";
    this.toolTip1.SetToolTip(this.button3, "点击此按钮,程序自动将新广告存入库中");
    this.button3.Click += new System.EventHandler(this.button3_Click);
    // 
    // groupBox1
    // 
    this.groupBox1.BackColor = System.Drawing.SystemColors.Info;
    this.groupBox1.Controls.Add(this.button2);
    this.groupBox1.Controls.Add(this.textBox1);
    this.groupBox1.Controls.Add(this.button3);
    this.groupBox1.Controls.Add(this.button1);
    this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.groupBox1.Location = new System.Drawing.Point(8, 0);
    this.groupBox1.Name = "groupBox1";
    this.groupBox1.Size = new System.Drawing.Size(352, 80);
    this.groupBox1.TabIndex = 5;
    this.groupBox1.TabStop = false;
    // 
    // groupBox2
    // 
    this.groupBox2.Controls.Add(this.dataGrid1);
    this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
    this.groupBox2.Location = new System.Drawing.Point(8, 96);
    this.groupBox2.Name = "groupBox2";
    this.groupBox2.Size = new System.Drawing.Size(352, 224);
    this.groupBox2.TabIndex = 6;
    this.groupBox2.TabStop = false;
    this.groupBox2.Text = "新广告";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.BackColor = System.Drawing.SystemColors.Info;
    this.ClientSize = new System.Drawing.Size(370, 327);
    this.Controls.Add(this.groupBox2);
    this.Controls.Add(this.groupBox1);
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
    this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
    this.MaximizeBox = false;
    this.Name = "Form1";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "新广告提取程序";
    this.TransparencyKey = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)), ((System.Byte)(64)));
    this.Load += new System.EventHandler(this.Form1_Load);
    ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
    this.groupBox1.ResumeLayout(false);
    this.groupBox2.ResumeLayout(false);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    string tableName=null;
    if(this.openFileDialog1 .ShowDialog() ==DialogResult.OK )
    {
    tableName=this.openFileDialog1.FileName ;
    tableName=tableName.Substring(tableName.LastIndexOf("\\")+1);
    tableName=tableName.Remove(tableName.Length-4,4);
    this.textBox1.Text =tableName;
    }

    } private void button2_Click(object sender, System.EventArgs e)
    {
      

    string commandText="SELECT DISTINCT  TITLE, LANG, CONTROL, PTYPE FROM `" +this.textBox1.Text+"`"+"WHERE TITLE NOT IN(SELECT  TITLE FROM `RawBase`  ) AND PGADS='A'" ;
    this.odbcCom.CommandText =commandText;
    this.odbcCom.Connection =this.odbcCon ;
    this.odbcAd =new OdbcDataAdapter(this.odbcCom.CommandText ,this.odbcCon .ConnectionString );
    try
    {
    this.odbcCon .Open();
    ds.Clear();
    this.odbcAd .Fill (ds);
    this.dataGrid1.DataSource =ds.Tables[0];
    this.groupBox2.Text="新广告 : "+ds.Tables[0].Rows.Count +"条";
    this.button3 .Enabled =true;

    }
    catch(Exception ee)
    {MessageBox.Show (ee.ToString ());}
    finally
    {this.odbcCon.Close ();}


    } private void button3_Click(object sender, System.EventArgs e)
    {
    if(ds.Tables.Count==0||ds.Tables[0].Rows.Count==0)
    {MessageBox.Show ("没有新广告。");
       return;}
    try
    {
    this.odbcCom =new OdbcCommand() ;
    this.odbcCom.Connection =this.odbcCon ;
    for (int i=0;i<ds.Tables[0].Rows.Count ;i++)
    {   
    this.odbcCom.CommandText="INSERT INTO `RawBase`(TITLE,LANG,CONTROL,PTYPE) VALUES("
    +"'"+ds.Tables[0].Rows[i][0]+"',"
    +"'"+ds.Tables [0].Rows[i][1]+"',"
    +"'"+ds.Tables [0].Rows[i][2]+"',"
    +"'"+ds.Tables[0].Rows[i][3]+"')";

    if(this.odbcCon.State!=ConnectionState.Open )
    {
    this.odbcCon.Open();
    }

    this.odbcCom .ExecuteNonQuery();


    }
    MessageBox.Show ("导入完成!");
    this.button3.Enabled =false;
    }
    catch(Exception ee)
    {MessageBox.Show ("导入失败"+"\r\n"+"原因如下:"+"\r\n"+ee.ToString ());}
    finally
    {

    this.odbcCon.Close ();
    }

                    
      

    } private void Form1_Load(object sender, System.EventArgs e)
    {
    this.odbcCon=new OdbcConnection();
    this.odbcCon.ConnectionString = "MaxBufferSize=2048;FIL=dBase 5.0;DSN=dbfbase;PageTimeout=5;DefaultDir="+Application.StartupPath.ToString()+"\\DBFS;DriverId=533";
    this.odbcCom=new OdbcCommand();

    }
    }
    }
      

  4.   

    copyright reserved
    数据源还得自己配制
      

  5.   

    你們寫得大致一樣,但是,我要的是這樣一種效果
    string [] fileList={"dbf1","dbf2","dbf3","dbf4","dbf5"...};
    int i=0;
    while(i++ < fileList.Length)
    {
        string tempName = fileList[i];
        打開tempName.dbf
        得到tempName的記錄集
        遍歷並輸出記錄集中一個名叫orderno的字段值
    }....
    所以,我請教大家一個比好的,適合循環打開方式,而不要每次循環都要用 new delete