Beispiel #1
0
        public static DataTable ConvertRecordset(Recordset rs)
        {
            DataTable table = null;
            int       num;

            if (rs != null)
            {
                Hashtable hashtable = new Hashtable();
                table = new DataTable();
                for (num = 0; num < rs.Fields.Count; num++)
                {
                    string name = rs.Fields[num].Name;
                    if (!table.Columns.Contains(name))
                    {
                        table.Columns.Add(name);
                    }
                    else
                    {
                        if (hashtable[name] != null)
                        {
                            hashtable[name] = int.Parse(hashtable[name].ToString()) + 1;
                        }
                        else
                        {
                            hashtable[name] = "1";
                        }
                        table.Columns.Add(name + "_" + hashtable[name]);
                    }
                }
            }
            if (!rs.EOF)
            {
                object[,] objArray = (object[, ])rs.GetType().InvokeMember("GetRows", BindingFlags.InvokeMethod, null, rs, new object[0]);
                int length = objArray.GetLength(1);
                int num3   = objArray.GetLength(0);
                for (num = 0; num < length; num++)
                {
                    object[] values = new object[num3];
                    for (int i = 0; i < num3; i++)
                    {
                        values[i] = objArray[i, num];
                    }
                    table.Rows.Add(values);
                }
            }
            return(table);
        }