Nonagon
Nonagon

Reputation: 407

Populating rows with data from a stored procedure using DataTables

I want to populate some fields on a PDF with data from a SQL database, I have a data access class that works but I can't get the values from the rows:

DataAccess DA = new DataAccess();

DataSet S = DA.CashData();

DataTable Cash = S.Tables[0];
DataTable Other = S.Tables[1];
DataTable Check = S.Tables[2];
DataTable Else = S.Tables[3];

string s = "";

foreach (DataRow row in Cash.Rows)
{
    foreach (DataColumn col in Cash.Columns)
    {
        for (int i = 0; i < Cash.Columns.Count; i++)
        {
            DataRow cashRow = Cash.Rows[i];
            s = s + cashRow[0].ToString() + ";";
        }
    }

    Console.ReadLine();
}

string[] data = s.Split(';');
cell32.AddElement(new Paragraph(""));
cell32.AddElement(new Paragraph(data[0]));
cell32.AddElement(new Paragraph(data[1]));

The columns show data but the rows do not

Upvotes: 0

Views: 41

Answers (1)

jomsk1e
jomsk1e

Reputation: 3625

If I understand your source correctly, you have a wrong execution in your loop for the rows, please consider this edited source:

DataAccess DA = new DataAccess();
DataSet S = DA.CashData();
DataTable Cash = S.Tables[0];
DataTable Other = S.Tables[1];
DataTable Check = S.Tables[2];
DataTable Else = S.Tables[3];
string s = "";

foreach (DataRow row in Cash.Rows)
{
    for (int i = 0; i < row.Columns.Count; i++)
    {
        s += row[0].ToString() + ";";
    }
    Console.ReadLine();
}

string[] data = s.Split(';');
cell32.AddElement(new Paragraph(""));
cell32.AddElement(new Paragraph(data[0]));
cell32.AddElement(new Paragraph(data[1]));

Upvotes: 1

Related Questions