0

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

1 Answer 1

1

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]));
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jomsk1e Changing the 0 in row[0].ToString to row row[i].Tostring seems to have done the trick! thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.