如何循环访问 DataRow 来检索一组相关列,即(参数名称、参数类型和参数值)?

发布于 2024-07-14 02:56:31 字数 367 浏览 10 评论 0原文

我正在开发一个通用报告工具,其中每个报告都由数据库中报告表中的一行表示。

报告行结构:

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

那么,我需要检索报告参数(名称、类型和值)并循环遍历它们以将它们传递给报告?

仅供参考:参数类型:日期或字符串。 我正在使用嵌入 VS.NET 2005 的 CrystalReport 设计器。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南薇 2024-07-21 02:56:31

好吧,虽然我不知道你到底要做什么,但我只会给你一个我所做的例子,你可以接受或放弃它。

为您提供一些细节。 这是连接到 Access 数据库的示例,但到其他类型数据库的连接在连接字符串方面是类似的。 查找连接字符串以获得正确的语法。

我还有一个名为 currentDataSet 的强类型数据集,以及一个定义的表,该表的名称和结构与数据库类型相同。 还有其他方法可以实现此目的,但这就是我所做的:

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();

从那里您可以操作数据集中的数据。 这里还是一个例子:

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;
}

从现在起,您现在可以使用以下代码更新数据库中的数据:

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

就像我说的,如果这些对您没有帮助,请随意忽略它,您不会伤害我的感情:)

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 :)

半边脸i 2024-07-21 02:56:31

当您说循环 DataRow 时,您的意思是:

DataRow drMyrow = MyTables.Rows[0];

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

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文