需要比较来自多个来源的数据表

时间:2014-09-08 23:46:29

标签: c# mysql sql datatable dataset

我正在尝试比较我从多个来源创建的DataTables和DataSet。我有一个从ExcelDataReader库创建的DataSet。其他信息来源是DataTables,来自下面的代码(如果更容易使用,我可以将它们变为DataSet而不是DataTables):

    public DataTable ImportFromSQLDB()
    {
        SqlConnection sql;
        string query = "SELECT ClassandSubClass FROM dbo.ClassCodes";
        sql = new SqlConnection(@"server=1.1.1.1;" + @"Trusted_Connection=false;" + @"uid=user;" +
                                @"password=password;" + @"database=Depot;");
        SqlCommand cmd = new SqlCommand(query, sql);
        DataTable sqlds = new DataTable();
        sql.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(sqlds);
        sql.Close();
        return sqlds;          
    }

    public DataTable ImportFromSQLDB2()
    {
        SqlConnection sql;
        string query = "SELECT SubClassCodeDescription FROM dbo.ClassCodes";
        sql = new SqlConnection(@"server=1.1.1.1;" + @"Trusted_Connection=false;" + @"uid=user;" +
                                @"password=password;" + @"database=Depot;");
        SqlCommand cmd = new SqlCommand(query, sql);
        DataTable sqlds2 = new DataTable();
        sql.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(sqlds2);
        sql.Close();
        return sqlds2;
    }

    public DataTable ImportFromMySQLDB()
    {
        string conn = ("Data Source=1.1.1.1;" + "Database=platform;" + "Username=user;" + "Password=password;");
        MySqlConnection mysql = new MySqlConnection(conn);
        DataTable mysqlds = new DataTable();
        string cmd = "SELECT platformname FROM masterlist ";
        mysql.Open();
        MySqlDataAdapter da = new MySqlDataAdapter(cmd, conn);
        da.Fill(mysqlds);
        mysql.Close();
        return mysqlds;
    }

    public DataTable ImportFromMySQLDB2()
    {
        string conn = ("Data Source=1.1.1.1;" + "Database=platform;" + "Username=user;" + "Password=password;");
        MySqlConnection mysql = new MySqlConnection(conn);
        DataTable mysqlds = new DataTable();
        string cmd = "SELECT codenameallsys FROM masterlist ";
        mysql.Open();
        MySqlDataAdapter da = new MySqlDataAdapter(cmd, conn);
        da.Fill(mysqlds);
        mysql.Close();
        return mysqlds;
    }

我想创建另一个方法来对任何两个DataTable进行比较,但是我对如何继续进行了迷失。任何帮助将不胜感激。

0 个答案:

没有答案