我想做一个windows forms程序,想把.txt的文件转换成.MDB的文件,怎么做呀?

解决方案 »

  1.   

    首先在Access数据库中新建一个数据库,再建表。并且对txt文件中的内容的格式要求很规范,要有规律,用程序读取txt文件,具体可参考http://support.microsoft.com/kb/306777/zh-cn等,将读到的数据按不同的含义分别放在新建好的表的不同字段中。一直这样循环读和写下去就可以。当然其中要有很多的容错处理,各种情况都要考虑到,比如txt文件已打开,txt文件内的数据格式有问题等。
      

  2.   

    那就把txt里的内容读出来,然后insert到MDB中去~
      

  3.   

    不能再Access里建表和建库,我要的是直接用所做的程序把txt的文件转换成.MDB的文件
      

  4.   

    我的意思是能不能用C#代码生成MDB文件
      

  5.   


    还是用代码去“Create Table ...”,然后建表,读txt,插入MDB
      

  6.   

    就是这意思“还是用代码去“Create Table ...”,然后建表,读txt,插入MDB”,可没这么做过,谁有代码,我参考下
      

  7.   

    lz参考下SqlServer的:如何用C#来部署数据库http://blog.csdn.net/knight94/archive/2006/03/19/628871.aspxhttp://blog.csdn.net/giantboy520/archive/2006/09/16/1230391.aspxhttp://blog.csdn.net/ltolll/archive/2006/08/30/1144628.aspx
      

  8.   

    我现在数据表建好了,txt数据也读出来了,那么现在怎么把数据插入到数据表里呀???
      

  9.   

    参考下行不行·            OleDbConnection conn = new OleDbConnection(General.Connstring);
                OleDbCommand cmdInsert = new OleDbCommand();
                OleDbDataAdapter adp = new OleDbDataAdapter();
                cmdInsert.Connection = conn;
                cmdInsert.Parameters.Add("@ON", OleDbType.VarChar, 20, "order_no");
                cmdInsert.Parameters.Add("@RN", OleDbType.BigInt, 11, "ref_no");
                cmdInsert.Parameters.Add("@OD", OleDbType.DBDate, 8, "order_date");
                cmdInsert.Parameters.Add("@CI", OleDbType.VarChar, 20, "customer_id");
                cmdInsert.Parameters.Add("@OP", OleDbType.VarChar, 20, "operator");
                //cmmInsert.Parameters.Add("@OT", OleDbType.DBDate, 8, "operate_time");
                //cmmInsert.CommandText = "insert into t_make_order(order_no,ref_no,order_date,customer_id,operator,operate_time) values(@ON,@RN,@OD,@CI,@OP,@OT)";
                cmdInsert.CommandText = "insert into t_make_order(order_no,ref_no,order_date,customer_id,operator) values(@ON,@RN,@OD,@CI,@OP)";
                OleDbTransaction _tran = null;
                try
                {
                    conn.Open();
                    _tran = conn.BeginTransaction();
                    cmdInsert.Transaction = _tran;
                    adp.InsertCommand = cmdInsert;
                    adp.Update(dtToInsert);
                    _tran.Commit();
                    MessageBox.Show("保存订单数据成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnExport.Focus();
                    return;
                }
                catch (OleDbException exc)
                {
                    if (_tran != null)
                    {
                        _tran.Rollback();
                        _tran = null;
                    }
                    MessageBox.Show(exc.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                catch (Exception ex)
                {
                    if (_tran != null)
                    {
                        _tran.Rollback();
                        _tran = null;
                    }
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Close();
                        conn = null;
                    }
                }
      

  10.   

    txt文件里的数据
    李红,女,24
    王刚,男,32
    数据库字段
    id自增,字段1,字段2,字段3,
    批量插入~ 是什么意思,我没这样做过,麻烦说明白点
      

  11.   


    (1)不连接,能行吗?只有一个办法,就是你了解Access的文件结构,直接将txt文档的内容转为Access(2)txt中的内容是SQL语句,在C#在执行然后转成Access,原理与MYSQL的备份还原一样(3)上面几楼都提供了方法,自己选一种楼主,想清楚要做什么了吗?当方法复杂就表示事情的方向可能出错了
      

  12.   


    自己写个mdb数据操作引擎,然后将txt文件中的内容读出以二进制的方式写入?