将Access数据库中数据导入到SQL Server中的详细方法实例

2019-05-20 11:52:08丽君

                sqlstr += "select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','" + AccessPath + "';'admin';'',Score)";
                SqlConnection conn = CreateSQLCon();
                conn.Open();
                SqlCommand mycom = new SqlCommand(sqlstr, conn);
                mycom.ExecuteNonQuery();//执行添加操作
                if (j == DT.Rows.Count - 1)
                {
                    Label1.Visible = true;
                    Label1.Text = "<script language=javascript>alert('数据导入成功.');location='AccessToSQL.aspx';</script>";
                }
                else
                {
                    Label1.Visible = true;
                    Label1.Text = "<script language=javascript>alert('数据导入失败.');location='AccessToSQL.aspx';</script>";
                }
                conn.Close();
            }
        }

    }
    public void AccessLoadData()
    {
        OleDbConnection myConn = CreateCon();
        myConn.Open();   //打开数据链接,得到一个数据集    
        DataSet myDataSet = new DataSet();   //创建DataSet对象    
        string StrSql = "select   *   from  Score";
        OleDbDataAdapter myCommand = new OleDbDataAdapter(StrSql, myConn);
        myCommand.Fill(myDataSet, "Score");