By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,828 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,828 IT Pros & Developers. It's quick & easy.

VB.Net to C# conversion phenomenon

P: n/a
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][i] == DBNull.Value || campCustomers == 0)
{
dr[i] = 0;
dr1[i] = 0;
}
else
{
dr[i] = (Convert.ToDouble (tbl.Rows[0][i]) / campCustomers *
100).ToString("#0.00");
dr1[i] = (Convert.ToDouble(tbl.Rows[0][i]) / campCustomers * 12 *
100).ToString("#0.00");
}
}

The interesting part is that under some in C# “ds.Tables[0].Rows[0][i]” does
not contain the data but I could get the date to define
“ds.Tables[0].Rows[1][i]”

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][i]”

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][i] == DBNull.Value || campCustomers == 0)
{
dr[i] = 0;
dr1[i] = 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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Chris,

This is in my opinion not a VBNet problem however a C#. In this newsgroup
most people are active with VBNet and know C#.

When you are active with something you see strange things mostly in a glimp.

Therefore why don't you use it in the CSharp newsgroup. There are a lot of
people who know VBNet however are active with C#.

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Cor,

thanks I posted in the C# section as well. It was not really a problem since
I found a workaround. I just wanted to know why it was behaving in that
manner...the answer can be found in the c# forum.

Sorry if I have misused the VB.Net forum

Chris

"Cor Ligthert [MVP]" wrote:
Chris,

This is in my opinion not a VBNet problem however a C#. In this newsgroup
most people are active with VBNet and know C#.

When you are active with something you see strange things mostly in a glimp.

Therefore why don't you use it in the CSharp newsgroup. There are a lot of
people who know VBNet however are active with C#.

I hope this helps,

Cor

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.