views:

1512

answers:

2

I'm working on a Generic Reporting Tool, where each report is represented by a row in Reports table in database.

Report row structure:

ReportID          ReportFileName  
RepParam1Name     RepParam1Type      RepParam1Value 
RepParam2Name     RepParam2Type      RepParam2Value   ... RepParam10

So, I need to retrieve report parameters (Name, Type, and Value) and loop through them to pass them to report?

FYI: Parameter Type: Date or String. I'm using CrystalReport designer embedded with VS.NET 2005.

A: 

Okay, so while I don't know exactly what you are heading for, I will just give you an example of what I did and you can take it or leave it.

A few details for you. This is an example of connecting to an Access Databse, but connections to other kinds of databases are similar in their connection strings. Look up connection strings for the correct syntax.

I also have a strongly typed DataSet called currentDataSet and a table defined that is named the same and structured the same as the database type. There are other ways of accomplishing this, but this is the way I did it:

string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sourceString;
string strSql1 = "SELECT * FROM ReportTable";
OleDbConnection con = new OleDbConnection(conString);
con.Open();
OleDbDataAdapter dAdapter = new OleDbDataAdapter();
dAdapter.SelectCommand = new OleDbCommand(strSql1, con);
dAdapter.Fill(currentDataSet, "ReportTable");
con.Close();

From there you can manipulate the data inside of the dataset. Again here is an example:

int reportTableCount = currentDataSet.ReportTable.Count();
int reportTableCounter = 0;

while (reportTableCounter < reportTableCount)
{
   if (currentDataSet.ReportTable[reportTableCounter].RepParam1Value == "Bad data")
   {
       currentDataSet.ReportTable[reportTableCounter].RepParam1Value = "Good data";
   }
    reportTableCounter = reportTableCounter + 1;
}

From this point you can now update the data in the database with the following code:

con.Open();
dAdapter.SelectCommand = new OleDbCommand(strSql1, con);
OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(dAdapter);
dAdapter.Update(currentDataSet, "ReportTable");
con.Close();

Like I said, if none of this helps you, feel free to disregard it, you won't hurt my feelings :)

Matt
A: 

When you say loop through a DataRow do you mean sommething like:

DataRow drMyrow = MyTables.Rows[0];

foreach (DataColumn dc in drMyRow) { //do something with the column }

Davy