string sql = "";
OleDbConnection con = CreateCon();//创建数据库连接
con.Open();
DataSet ds = new DataSet(); //创建数据集
sql = "select * from Score";
OleDbDataAdapter myCommand = new OleDbDataAdapter(sql,con);//创建数据适配器
myCommand.Fill(ds, "Score");
myCommand.Dispose();
DataTable DT = ds.Tables["Score"];
con.Close();
myCommand.Dispose();
for (int j = 0; j < DT.Rows.Count; j++)//循环ACCESS中数据获取相应信息
{
string sqlstr = "";
string ID = DT.Rows[j][0].ToString();
string UserName = DT.Rows[j][1].ToString();
string PaperName = DT.Rows[j][2].ToString();
string UserScore = DT.Rows[j][3].ToString();
string ExamTime = DT.Rows[j][4].ToString();
string selsql = "select count(*) from AccessToSQL where 用户姓名='" + UserName + "'";
if (ExScalar(selsql) > 0)//判断数据是否已经添加
{
Label1.Visible = true;
Label1.Text = "<script language=javascript>alert('该Access数据库中数据已经导入SQL数据库中!');location='AccessToSQL.aspx';</script>";
}
else
{
string AccessPath = Server.MapPath("UserScore.mdb");//获取ACCESS数据库路径
//应用OPENROWSET函数访问 OLE DB 数据源中的远程数据所需的全部连接信息
sqlstr = "insert into AccessToSQL(ID,用户姓名,试卷,成绩,考试时间)Values('" + ID + "','" + UserName + "','" + PaperName + "','" + UserScore + "','" + ExamTime + "')";








