Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My current Code:
IDictionary<string, DataTable> allTables = new Dictionary<string, DataTable>();
            foreach (string table in tableNames)
            {
                DataTable dtbl = new DataTable();
                string selectQuery = "SELECT * FROM " + table;
                allTables.Add(table, new DataTable());

                SQLiteCommand cmd = new SQLiteCommand(selectQuery, liteCon);
                SQLiteDataAdapter sqliteDAP = new SQLiteDataAdapter(cmd);
                sqliteDAP.Fill(allTables[table]);

                foreach (DataRow row in allTables[table].Rows)
                {
                    Console.WriteLine(row); // This is where I want to see the actual values
                }

            }


What I'm trying to do is access the ItemArray value in the "Rows" class/object for allTables[table]. The data that I am looking for is located in ItemArray as can be seen here[^]

What I have tried:

I've tried
Console.WriteLine(row);

But that just returns System.Data.DataRow
Posted
Updated 18-Sep-20 14:40pm

C#
private void PrintTable(DataTable table)
{
    foreach(DataRow row in table.Rows)
    {
        foreach(DataColumn column in table.Columns)
        {
            Console.WriteLine(row[column]);
        }
    }
}


DataRow.ItemArray Property (System.Data) | Microsoft Docs[^]
 
Share this answer
 
Look at thus code:
DataTable dtbl = new DataTable();
string selectQuery = "SELECT * FROM " + table;
allTables.Add(table, new DataTable());
you declare a DataTable variable dtbl, then never use it.

this is how you can use the ItemArray:
foreach (KeyValuePair<string, DataTable> kvp in AllTables)
{
    Console.WriteLine($"Table: {kvp.Key}");

    foreach (DataRow drw in kvp.Value.Rows)
    {
        Console.WriteLine($"\tRow: {kvp.Value.Rows.IndexOf(drw)}");

        for (var j = 0; j < drw.ItemArray.Length; j++)
        {
            var itm = drw.ItemArray[j];
            Console.WriteLine($"\t\tItm {j}: {itm}");
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900