Translate C# to VB.net?

T

Tmuld

Oh man - there is a great example here:

http://www.c-sharpcorner.com/Code/2003/July/NavigationSystemInASPNet.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.
 
M

Marcie Jones

You need to do that all on one line:

Dim MyArray() As String =
{dcol.ColumnName.ToString(),dr(dcol.ColumnName.ToString()).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
 
T

Tmuld

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.ToString()).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.ToString()).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.
 
M

Marcie Jones

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
 
T

Tmuld

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
 
M

Marcie Jones

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
 
C

Chris Dunaway

Try this:

MyArray = New String() {...} 'use New here

Otherwise you will have to put the Dim inside the loop
 
T

Tmuld

Thanks for the help!

This is where I am trying to translate the code from:
http://www.c-sharpcorner.com/Code/2003/July/NavigationSystemInASPNet.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.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}

Where is that put?

Yup, still learning VB.NET

Thanks,

Tmuld
 

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