473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB.Net to C# conversion phenomenon

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
2 1364
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
4
by: Eric | last post by:
I found the following phenomenon in VC++ 2005: struct A {}; struct B : public A { virtual ~B() {} }; A* p = new B;
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjrn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
11
by: tthunder | last post by:
Hi @all, My small example does not compile... I know, that this (as always) has reasons, but I want to know WHY? BTW: I only get errors with g++ (4.x), BCB (6.0),... VS C++ (2005) works...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.