none
Merging Data Sets from Two Different Databases - for RDLC Report RRS feed

  • Question

  • I am familiar generating a report with single data set as source, but now i have two datasets from two different databases, one has all the customer information and the other has one column customer_type which i want to use in the RDLC report,  both datasets are of different schemas and both on different servers , also the login credentilas for both the databses are different. So i cant refer other databse in sql by using servername.databasename.schema.tablename.

    From basic research i found out there are two ways to acheive this.

    1. use merge method - My datasets are of different scemas, can i still use this method?

    2. use list  - How can i acheive my functinlaoty by using a list?

    Tuesday, April 24, 2012 12:19 AM

Answers

  • Hi yuvaratna,

    Welcome to MSDN Forum.

    -> use merge method - My datasets are of different scemas, can i still use this method?

    Yes, you can use merge method. This method will Merge a specified DataSet and its schema into the current DataSet. Please refer to this link: DataSet.Merge Method. In this link, there's a good demo can help you to merge the two dataset.

    -> use list  - How can i acheive my functinlaoty by using a list?

    You need to query out the records as two List<T>, then create a new List<T> to contain all the elements in the two lists. I suppose the first list contains testA type records and the second list contains testB type records. Below is an example, please refer to it.

    class testA
        {
            public int id { get; set; }
            public string name { get; set; }
        }
    
        class testB
        {
            public bool sex { get; set; }
        }
    
        class mergedType
        {
            public testA ta { get; set; }
            public testB tb { get; set; }
    
            public mergedType(testA a, testB b)
            {
                ta = a;
                tb = b;
            }
    
            public List<mergedType> Merge(List<testA> testAList, List<testB> testBList)
            {
                if (testAList.Count != testBList.Count)
                {
                    throw new ArgumentException("The two lists must have the same length.");
                }
    
                List<mergedType> mergedList = new List<mergedType>();
                
                for (int i = 0; i < testAList.Count; i++)
                {
                    mergedList.Add(new mergedType(testAList[i], testBList[i]));
                }
    
                return mergedList;
            }
        }

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 25, 2012 3:04 AM
    Moderator