SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Free VB.NET to C# translator...

rated by 0 users
This post has 2 Replies | 1 Follower

Top 10 Contributor
Posts 1,096
microlau Posted: 11-14-2005 9:18 AM
Works for C# to VB.NET as well.

microlau Blog: http://community.sgdotnet.org/blogs/microlau

Top 10 Contributor
Posts 2,284

Doesn't convert "perfectly". Try this code snippet, it will continue to use ( ) parenthesis instead of [ ] square brackets for array and DataRow indexes.

Dim Keys(1) As DataColumn

' create a data table
Dim dt As New DataTable("TableTest")

' create a number column
Dim dcNumber As New DataColumn("NumberColumn", GetType(Int32))
dt.Columns.Add(dcNumber)

' add this column to the keys array, apply as primary key
Keys(0) = dcNumber
dt.PrimaryKey = Keys

' create a string column
Dim dcString As New DataColumn("StringColumn", GetType(String))
dcString.MaxLength = 50
dt.Columns.Add(dcString)

' create a date column
Dim dcDate As New DataColumn("DateColumn", GetType(Date))
dt.Columns.Add(dcDate)

' add a row
Dim row As DataRow = dt.NewRow()
row("NumberColumn") = 1
row("StringColumn") = "Test on row 1"
row("DateColumn") = Now
dt.Rows.Add(row)

' add a second row
row = dt.NewRow()
row("NumberColumn") = 2
row("StringColumn") = "Test on row 2"
row("DateColumn") = Now.AddDays(1)
dt.Rows.Add(row)

' bind the table to the grid
UltraGrid1.DataSource = dt

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Top 10 Contributor
Posts 1,096

Hmm.. Interesting. Here's the C# codes after conversion:

DataColumn[,] Keys;
DataTable dt = new DataTable("TableTest");
DataColumn dcNumber = new DataColumn("NumberColumn", typeof(Int32));
dt.Columns.Add(dcNumber);


//  add this column to the keys array, apply as primary key
Keys(0) = dcNumber;
dt.PrimaryKey = Keys;
DataColumn dcString = new DataColumn("StringColumn", typeof(string));
dcString.MaxLength = 50;
dt.Columns.Add(dcString);
DataColumn dcDate = new DataColumn("DateColumn", typeof(DateTime));
dt.Columns.Add(dcDate);
DataRow row = dt.NewRow();
row("NumberColumn") = 1;
row("StringColumn") = "Test on row 1";
row("DateColumn") = Now;
dt.Rows.Add(row);

//  add a second row
row = dt.NewRow();
row("NumberColumn") = 2;
row("StringColumn") = "Test on row 2";
row("DateColumn") = Now.AddDays(1);
dt.Rows.Add(row);

//  bind the table to the grid
UltraGrid1.DataSource = dt;

microlau Blog: http://community.sgdotnet.org/blogs/microlau

Page 1 of 1 (3 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems