G
Guest
I had the following VB.Net code
ds.Tables.Add(BindData(camp_id, grid_id, cbo.SelectedValue, "CAMP"))
tbl = BindData(camp_id, grid_id, cbo.SelectedValue, "CHURN")
ds.Tables(0).ImportRow(tbl.Rows(0))
For i = 1 To ds.Tables(0).Columns.Count - 1
If IsDBNull(tbl.Rows(0).Item(i)) Or campCustomers = 0 Then
dr(i) = 0
dr1(i) = 0
Else
dr(i) = Format(tbl.Rows(0).Item(i) / CInt(campCustomers) * 100,
"0.00")
dr1(i) = Format(tbl.Rows(0).Item(i) / CInt(campCustomers) * 12 *
100, "0.00")
End If
next
Which I translated into C# like this
ds.Tables.Add(BindData(camp_id, grid_id, Convert.ToInt32(cbo.SelectedValue),
"CAMP"));
tbl = BindData(camp_id, grid_id, Convert.ToInt32(cbo.SelectedValue), "CHURN");
ds.Tables[0].ImportRow(tbl.Rows[0]);
for (int i = 1; i <= ds.Tables[0].Columns.Count - 1; i++)
{
if (ds.Tables[0].Rows[0] == DBNull.Value || campCustomers == 0)
{
dr = 0;
dr1 = 0;
}
else
{
dr = (Convert.ToDouble (tbl.Rows[0]) / campCustomers *
100).ToString("#0.00");
dr1 = (Convert.ToDouble(tbl.Rows[0]) / campCustomers * 12 *
100).ToString("#0.00");
}
}
The interesting part is that under some in C# “ds.Tables[0].Rows[0]†does
not contain the data but I could get the date to define
“ds.Tables[0].Rows[1]â€
And under some circumstances “ds.Tables.Add(BindData(camp_id, grid_id,
cbo.SelectedValue, "CAMP"))†returns a null value. Hence I have to access the
data with “ds.Tables[0].Rows[0]â€
In VB.Net that does not cause any problems it seems it always accesses the
“right†row even if “ds.Tables.Add(BindData(camp_id, grid_id,
cbo.SelectedValue, "CAMP"))†returns null.
I found a (dodgy) workaround in C# to test what value is in the row and then
define which rownumber to use.
If “ds.Tables.Add(BindData(camp_id, grid_id,
Convert.ToInt32(cbo.SelectedValue), "CAMP"));†did not return null I got
these values in the datasets rows
ds.Tables[0].Rows[0][0] "Campaign"
ds.Tables[0].Rows[1][0] "CHURN"
If it returned a null
ds.Tables[0].Rows[0][0] "Churn"
ds.Tables[0].Rows[1][0] error: object 'ds.Tables[0].Rows[1]' doesn't have
an indexer
So now I check
if (ds.Tables[0].Rows[0][0].ToString().Equals("Campaign"))
intRowId = 1;
else
intRowId = 0;
for (int i = 1; i <= ds.Tables[0].Columns.Count - 1; i++)
{
if (ds.Tables[0].Rows[intRowId] == DBNull.Value || campCustomers == 0)
{
dr = 0;
dr1 = 0;
……..
I am surprised that the C# translation does not behave in the same manner as
the VB.Net version. Can someone please explain why that is? Or did I
mistranslate?
I hope I did not confuse you guys to much….
Thanks a lot
Chris
ds.Tables.Add(BindData(camp_id, grid_id, cbo.SelectedValue, "CAMP"))
tbl = BindData(camp_id, grid_id, cbo.SelectedValue, "CHURN")
ds.Tables(0).ImportRow(tbl.Rows(0))
For i = 1 To ds.Tables(0).Columns.Count - 1
If IsDBNull(tbl.Rows(0).Item(i)) Or campCustomers = 0 Then
dr(i) = 0
dr1(i) = 0
Else
dr(i) = Format(tbl.Rows(0).Item(i) / CInt(campCustomers) * 100,
"0.00")
dr1(i) = Format(tbl.Rows(0).Item(i) / CInt(campCustomers) * 12 *
100, "0.00")
End If
next
Which I translated into C# like this
ds.Tables.Add(BindData(camp_id, grid_id, Convert.ToInt32(cbo.SelectedValue),
"CAMP"));
tbl = BindData(camp_id, grid_id, Convert.ToInt32(cbo.SelectedValue), "CHURN");
ds.Tables[0].ImportRow(tbl.Rows[0]);
for (int i = 1; i <= ds.Tables[0].Columns.Count - 1; i++)
{
if (ds.Tables[0].Rows[0] == DBNull.Value || campCustomers == 0)
{
dr = 0;
dr1 = 0;
}
else
{
dr = (Convert.ToDouble (tbl.Rows[0]) / campCustomers *
100).ToString("#0.00");
dr1 = (Convert.ToDouble(tbl.Rows[0]) / campCustomers * 12 *
100).ToString("#0.00");
}
}
The interesting part is that under some in C# “ds.Tables[0].Rows[0]†does
not contain the data but I could get the date to define
“ds.Tables[0].Rows[1]â€
And under some circumstances “ds.Tables.Add(BindData(camp_id, grid_id,
cbo.SelectedValue, "CAMP"))†returns a null value. Hence I have to access the
data with “ds.Tables[0].Rows[0]â€
In VB.Net that does not cause any problems it seems it always accesses the
“right†row even if “ds.Tables.Add(BindData(camp_id, grid_id,
cbo.SelectedValue, "CAMP"))†returns null.
I found a (dodgy) workaround in C# to test what value is in the row and then
define which rownumber to use.
If “ds.Tables.Add(BindData(camp_id, grid_id,
Convert.ToInt32(cbo.SelectedValue), "CAMP"));†did not return null I got
these values in the datasets rows
ds.Tables[0].Rows[0][0] "Campaign"
ds.Tables[0].Rows[1][0] "CHURN"
If it returned a null
ds.Tables[0].Rows[0][0] "Churn"
ds.Tables[0].Rows[1][0] error: object 'ds.Tables[0].Rows[1]' doesn't have
an indexer
So now I check
if (ds.Tables[0].Rows[0][0].ToString().Equals("Campaign"))
intRowId = 1;
else
intRowId = 0;
for (int i = 1; i <= ds.Tables[0].Columns.Count - 1; i++)
{
if (ds.Tables[0].Rows[intRowId] == DBNull.Value || campCustomers == 0)
{
dr = 0;
dr1 = 0;
……..
I am surprised that the C# translation does not behave in the same manner as
the VB.Net version. Can someone please explain why that is? Or did I
mistranslate?
I hope I did not confuse you guys to much….
Thanks a lot
Chris