|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Translate C# to VB.net?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. 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 Show quoteHide quote On 12 Apr 2005 12:06:08 -0700, "Tmuld" <tmuld***@spliced.com> wrote: >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. 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. 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 Show quoteHide quote On 12 Apr 2005 12:42:52 -0700, "Tmuld" <tmuld***@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.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. 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 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 Show quoteHide quote On 12 Apr 2005 13:33:12 -0700, "Tmuld" <tmuld***@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 Try this:
>>For Each dr In ds.Tables(0).Rows MyArray = New String() {...} 'use New here>> For Each dcol In ds.Tables(0).Columns >>Newds.Tables(0).Rows.Add(MyArray) Otherwise you will have to put the Dim inside the loop>> Next >>Next >>Return Newds From our Instant VB converter:
Public Function GoDoReShape(ByVal ds As DataSet) As DataSet Dim NewDs As DataSet = 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") For Each dr As DataRow In ds.Tables (0).Rows For Each dcol As System.Data.DataColumn In ds.Tables(0).Columns 'Declare Array Dim MyArray As String()={dcol.ColumnName.ToString(),dr(dcol.ColumnName.ToString()).ToString()} NewDs.Tables(0).Rows.Add(MyArray) Next dcol Next dr Return NewDs End Function David Anton www.tangiblesoftwaresolutions.com Home of the Instant C# VB.NET to C# converter and the Instant VB C# to VB.NET converter Show quoteHide quote "Tmuld" wrote: > 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. > > 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
Splash window
ASCII lookup table VB.NET Equiv of... AxWebBrowser1 and code behind redirecting Datagrid - shown vertically instead of horizontally? Assigning a Null to Datetime Variable or Object Timer Event Not Firing in SystemFileWatcher... MDIParent property [ANN] April 12, 2005, "Visual Basic 2005 Language Enhancements" chat System Dsn creation from vb.net ? |
|||||||||||||||||||||||