用c# 将sql server数据库数据迁移到access数据库

         public void hexinchuli(string riqi)
        {

           //链接到sql server数据库,将需要数据迁移到access数据库相应的表
            string sqlserver = "Server =server;DataBase=database;Uid=sa;Pwd=123456";
            string Access = "Provider = Microsoft.Jet.OleDb.4.0;Data Source = E://mymymy//backfile//" + riqi + ".mdb";
           DataSet sqlds = new DataSet();
            SqlConnection sqlconn = new SqlConnection(sqlserver);
            sqlconn.Open();
            System.IO.StringWriter sqlXML = new System.IO.StringWriter();
            try
            {
                SqlDataAdapter mycommand = new SqlDataAdapter("select * from biao where syrp='"+riqi+"'", sqlconn);
                mycommand.Fill(sqlds, "biao");

                sqlds.WriteXml(sqlXML);
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(sqlXML.ToString());
                doc.Save("e://mymymy//dd.xml");
            }
            catch (Exception ex)
            {
                shengcheng.WriteToFile(ex.ToString());
            }
            sqlconn.Close();
            OleDbConnection oleconn = new OleDbConnection(Access);
            oleconn.Open();
            System.IO.StringWriter oleXML = new System.IO.StringWriter();
            try
            {
                OleDbDataAdapter olecomm = new OleDbDataAdapter("select * from biao", oleconn);
                DataSet oleds = new DataSet();
                OleDbCommandBuilder cb = new OleDbCommandBuilder(olecomm);
                oleds.ReadXml("e://mymymy//dd.xml");
                oleds.WriteXml(oleXML);
                olecomm.Update(oleds, "biao");
                oleds.AcceptChanges();
                System.IO.File.Delete("e://mymymy//dd.xml");
            }
            catch (Exception ex)
            {
                shengcheng.WriteToFile(ex.ToString());
            }
            oleconn.Close();
       
        }

你可能感兴趣的:(用c# 将sql server数据库数据迁移到access数据库)