iterate through a dataset

G

Guest

I am using the following code:

public DataView CreateReportDataSource()
{
string reportConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString()
+ "";
string reportSelect = Session["sqlSelect"].ToString();

oda = new OleDbDataAdapter(reportSelect, reportConnect);
DataSet ds = new DataSet();
oda.Fill(ds, "report");
DataView report = ds.Tables["report"].DefaultView;
countLabel.Text = report.Count + " Total Work Orders";
countLabel.Visible = true;
return report;
}

The reportSelect statement returns a field named wo16. I want to interate
through the dataset and when wo16 = null I wan tot replace it with "NO". How
do I alter my code to accomplish this task?

Thanks,

Dave
 
D

DotNet Coder

hi kscdavefl,

I would not recommend doing this in your C# code. I would recommend that you
do this on the database side in your stored procedure or sql statement. Make
use of the ISNULL function. It will provide the exact functionality that you
are looking for.

<code>
SELECT Col1, Col2, ISNULL(Col3, 'NO') as 'Col3' FROM Table
</code>

If you have to do it in your C# code, then this is generally the way you
should do it.

<code>
DataSet ds = new DataSet();
foreach(DataTable dt in ds.Tables)
{
foreach(DataRow row in dt.Rows)
{
foreach(DataColumn dc in dt.Columns)
{
if(dc.ColumnName == 'w016')
{
row[dc] = "NO";
break;
}
}
}
}
</code>

I didn't have a chance to test the code, but in theory, it should work, but
again, it is not suggested.

HTH,
~d
 
G

Guest

Thanks, I'll try this.

DotNet Coder said:
hi kscdavefl,

I would not recommend doing this in your C# code. I would recommend that you
do this on the database side in your stored procedure or sql statement. Make
use of the ISNULL function. It will provide the exact functionality that you
are looking for.

<code>
SELECT Col1, Col2, ISNULL(Col3, 'NO') as 'Col3' FROM Table
</code>

If you have to do it in your C# code, then this is generally the way you
should do it.

<code>
DataSet ds = new DataSet();
foreach(DataTable dt in ds.Tables)
{
foreach(DataRow row in dt.Rows)
{
foreach(DataColumn dc in dt.Columns)
{
if(dc.ColumnName == 'w016')
{
row[dc] = "NO";
break;
}
}
}
}
</code>

I didn't have a chance to test the code, but in theory, it should work, but
again, it is not suggested.

HTH,
~d

kscdavefl said:
I am using the following code:

public DataView CreateReportDataSource()
{
string reportConnect = "Provider=\"MSDAORA.1\";" + GetConnectionString()
+ "";
string reportSelect = Session["sqlSelect"].ToString();

oda = new OleDbDataAdapter(reportSelect, reportConnect);
DataSet ds = new DataSet();
oda.Fill(ds, "report");
DataView report = ds.Tables["report"].DefaultView;
countLabel.Text = report.Count + " Total Work Orders";
countLabel.Visible = true;
return report;
}

The reportSelect statement returns a field named wo16. I want to interate
through the dataset and when wo16 = null I wan tot replace it with "NO".
How
do I alter my code to accomplish this task?

Thanks,

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top