473,508 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Translate C# to VB.net?

Oh man - there is a great example here:

http://www.c-sharpcorner.com/Code/20...emInASPNet.asp

In C# (I think) but I am having difficult converting it to VB.NET.

Especially this part:

public DataSet GoDoReShape(DataSet ds)
{
DataSet NewDs=new DataSet();

NewDs.Tables.Add();
//Create Two Columns with names "ColumnName" and "Value"
//ColumnName -> Displays all ColumnNames
//Value -> Displays ColumnData
NewDs.Tables[0].Columns.Add("ColumnName");
NewDs.Tables[0].Columns.Add("Value");

foreach(DataRow dr in ds.Tables [0].Rows )
{
foreach(System.Data.DataColumn dcol in ds.Tables[0].Columns)
{
//Declare Array

string[]MyArray={dcol.ColumnName.ToString(),dr[dcol.ColumnName.ToString()].ToString()};
NewDs.Tables[0].Rows.Add(MyArray);
}
}
return NewDs;
}
I am not sure what the string[]MyArray <the rest> is telling me.

Should I dim MyArray as a string or as an Array - me thinks array.

So I tried it.

Dim myArray as Array

MyArray={dcol.ColumnName.ToString(),dr[dcol.ColumnName.ToString()].ToString()}
~
I get a squiggly saying 'Expression Expected'.

Or do I have this wrong?

Thanks,

Tmuld.

Nov 21 '05 #1
7 1478
You need to do that all on one line:

Dim MyArray() As String =
{dcol.ColumnName.ToString(),dr(dcol.ColumnName.ToS tring()).ToString()}

(I also changed the C#ian square brackets [] to parens for you).
Basically that is declaring an array of strings, and initializing it
with those two values--the column name and the corresponding value in
the DataReader for that column name.

Marcie

On 12 Apr 2005 12:06:08 -0700, "Tmuld" <tm******@spliced.com> wrote:
Oh man - there is a great example here:

http://www.c-sharpcorner.com/Code/20...emInASPNet.asp

In C# (I think) but I am having difficult converting it to VB.NET.

Especially this part:

public DataSet GoDoReShape(DataSet ds)
{
DataSet NewDs=new DataSet();

NewDs.Tables.Add();
//Create Two Columns with names "ColumnName" and "Value"
//ColumnName -> Displays all ColumnNames
//Value -> Displays ColumnData
NewDs.Tables[0].Columns.Add("ColumnName");
NewDs.Tables[0].Columns.Add("Value");

foreach(DataRow dr in ds.Tables [0].Rows )
{
foreach(System.Data.DataColumn dcol in ds.Tables[0].Columns)
{
//Declare Array

string[]MyArray={dcol.ColumnName.ToString(),dr[dcol.ColumnName.ToString()].ToString()};
NewDs.Tables[0].Rows.Add(MyArray);
}
}
return NewDs;
}
I am not sure what the string[]MyArray <the rest> is telling me.

Should I dim MyArray as a string or as an Array - me thinks array.

So I tried it.

Dim myArray as Array

MyArray={dcol.ColumnName.ToString(),dr[dcol.ColumnName.ToString()].ToString()}
~
I get a squiggly saying 'Expression Expected'.

Or do I have this wrong?

Thanks,

Tmuld.


Nov 21 '05 #2
Are you saying I can do this all in a loop?

For Each dr In ds.Tables(0).Rows

For Each dcol In ds.Tables(0).Columns
Dim MyArray() As String =
{dcol.ColumnName.ToString(),dr(dcol.ColumnName.ToS tring()).ToString()}

Newds.Tables(0).Rows.Add(MyArray)
Next
Next
Return Newds

I tried:

Dim MyArray() As String

<loops>
MyArray=
{dcol.ColumnName.ToString(),dr(dcol.ColumnName.ToS tring()).ToString()}
~ ('Expression Expected')
<end loops>

Still got the error.

I cannot put the dim statement in the loop - errors. Of course the
squigglies go away when I do (but show up under the Dim statement....)

Thanks,

Tmuld.

Nov 21 '05 #3
I don't get any squiggles when I paste that in--make sure that it all
appears on one line, it seems to be cutting off here in the NG post.

Marcie

On 12 Apr 2005 12:42:52 -0700, "Tmuld" <tm******@spliced.com> wrote:
Are you saying I can do this all in a loop?

For Each dr In ds.Tables(0).Rows

For Each dcol In ds.Tables(0).Columns
Dim MyArray() As String =
{dcol.ColumnName.ToString(),dr(dcol.ColumnName.To String()).ToString()}

Newds.Tables(0).Rows.Add(MyArray)
Next
Next
Return Newds

I tried:

Dim MyArray() As String

<loops>
MyArray=
{dcol.ColumnName.ToString(),dr(dcol.ColumnName.To String()).ToString()}
~ ('Expression Expected')
<end loops>

Still got the error.

I cannot put the dim statement in the loop - errors. Of course the
squigglies go away when I do (but show up under the Dim statement....)

Thanks,

Tmuld.


Nov 21 '05 #4
I have done this:

Dim Newds As New DataSet
Dim dr As DataRow
Dim dcol As DataColumn
Dim MyArray() As String
Newds.Tables.Add()
Newds.Tables(0).Columns.Add("ColumnName")
Newds.Tables(0).Columns.Add("Value")

For Each dr In ds.Tables(0).Rows
For Each dcol In ds.Tables(0).Columns

MyArray = {dcol.ColumnName.ToString(),
dr(dcol.ColumnName.ToString()).ToString()}

Newds.Tables(0).Rows.Add(MyArray)
Next
Next
Return Newds

Still getting the squibble ~ ('Expression Expected'). I cannot put the
Dim in a loop.

I am using VS 2003 if that help!

Again, many thanks for your patience!

Tmuld

Nov 21 '05 #5
Strange, I don't have any trouble Dimming an array inside a loop using
VS 2003. Here is the code I tried:

For i As Integer = 1 To 10
Dim MyArray() As String = {"a", "b"}
Next

Dimming the array each time just clears out the values.
Marcie

On 12 Apr 2005 13:33:12 -0700, "Tmuld" <tm******@spliced.com> wrote:
I have done this:

Dim Newds As New DataSet
Dim dr As DataRow
Dim dcol As DataColumn
Dim MyArray() As String
Newds.Tables.Add()
Newds.Tables(0).Columns.Add("ColumnName")
Newds.Tables(0).Columns.Add("Value")

For Each dr In ds.Tables(0).Rows
For Each dcol In ds.Tables(0).Columns

MyArray = {dcol.ColumnName.ToString(),
dr(dcol.ColumnName.ToString()).ToString()}

Newds.Tables(0).Rows.Add(MyArray)
Next
Next
Return Newds

Still getting the squibble ~ ('Expression Expected'). I cannot put the
Dim in a loop.

I am using VS 2003 if that help!

Again, many thanks for your patience!

Tmuld


Nov 21 '05 #6
Try this:
For Each dr In ds.Tables(0).Rows
For Each dcol In ds.Tables(0).Columns
MyArray = New String() {...} 'use New here
Newds.Tables(0).Rows.Add(MyArray)
Next
Next
Return Newds


Otherwise you will have to put the Dim inside the loop

Nov 21 '05 #7
Thanks for the help!

This is where I am trying to translate the code from:
http://www.c-sharpcorner.com/Code/20...emInASPNet.asp
In this part:
SqlConnection mycn;
SqlDataAdapter myda;
DataSet ds;
String strConn;
protected int intPageSize;

Where is this being put in the VB.NET code - in a subroutine or at the
top of the page - as public or private? I am not sure where to place
it?

Then comes the paging...

//Method 1-> Part b.
protected void PageRecords(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}

Where is that put?

Yup, still learning VB.NET

Thanks,

Tmuld

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2320
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
2014
by: shank | last post by:
I'm sure this is a stretch, but is there some kind of component that I could install to translate from English to Spanish on the fly? I have a lot of equipment features and specifications that I...
4
2136
by: Gadrin77 | last post by:
I have data that looks like <Root> <Main Value="Line1|Line2.|Line3|Line4.|Line5"/> </Root> I'm using Translate(@Value, "|.", ",")
6
2732
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
6
5539
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
1
9369
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
9
3086
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
1
2542
by: =?Utf-8?B?R2F1cmF2?= | last post by:
Hi, I am using the Translate() function in one of the .XSLT file to remove the spaces, like this: <xsl:for-each select=".//Illustration"> <xsl:value-of select="translate(./@illusName, ' ',...
3
4689
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
4
10615
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.