C#两个不同的数据库相同的表中导入数据

 /// 
        /// 将本地数据库数据更新到在线数据库中  SysLogin表
        /// 


        private void SysLogin_Sql()
        {
            String Sql = "select * from dbo.SysLogin";
            List IPim = new List();
            String connstr = ConfigurationManager.ConnectionStrings["SQLConnStringLocal"].ConnectionString;
            SqlConnection con = new SqlConnection(connstr);
            con.Open();
            SqlDataAdapter dtp = new SqlDataAdapter(Sql, con);
            try
            {
                DataTable dt = new DataTable();
                dtp.Fill(dt);
                foreach (var item in dt.Rows)
                {
                    SysLoginData models = new SysLoginData();

                    models.Id = ((DataRow)item)["id"].ToString();
                    models.UserName = ((DataRow)item)["UserName"].ToString();
                    models.Pwd = ((DataRow)item)["pwd"].ToString();
                    IPim.Add(models);
                }
            }
            catch
            {
                con.Close();
            }
            String SqlLine = "TRUNCATE TABLE dbo.SysLogin;";
            foreach (var item in IPim)
            {
                SqlLine += "insert into dbo.SysLogin values('" + item.Id + "','" + item.UserName + "','" + item.Pwd + "');";
                //selectSysLoginTwo(Sql2);
                String connstrLine = ConfigurationManager.ConnectionStrings["SQLConnStringLine"].ConnectionString;
                SqlConnection conLine = new SqlConnection(connstrLine);
                //SqlDataAdapter dtpLine = new SqlDataAdapter(SqlLine, conLine);
                try
                {
                    conLine.Open();
                    SqlCommand cmd = new SqlCommand(SqlLine, conLine);
                    int i = cmd.ExecuteNonQuery();
                }
                catch
                {
                    conLine.Close();
                }
            }
        }

你可能感兴趣的:(Winform)