C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » VB.NET Syntax »

Creating virtual table in vb.net using console application.


Posted Date: 21 Aug 2009    Resource Type: Code Snippets    Category: VB.NET Syntax
Author: NeetuMember Level: Diamond    
Rating: 1 out of 5Points: 6




This code helps u to create the virtual table. that u can bind with the datagridview. It does not use the backend.




Logic of this is first create the empty table that has no columns and rows.
then create the columns that u want and add it to the datatable after that finally create the data i.e rows according to columns and add it to the datatable.




Module Module1

Sub Main()
'Datatable is the collection of rows and columns.
Dim dt As DataTable

Dim col As DataColumn

Dim row As DataRow

dt = New DataTable

col = New DataColumn
'Caption indicates the heading of the column
col.Caption = "ID"
'Autoincrement will increase the value whenever row is added in the table.
col.AutoIncrement = True
'AutoIncrementSeed means starting value of the column
col.AutoIncrementSeed = 1
'AutoIncrementStep means increasing value if starting is 1 and step is 2 then it will increase as 1,3,5 and so on.
col.AutoIncrementStep = 1
'Columns.add(col) will add the column inside the datatable.
dt.Columns.Add(col)
'After adding the col in datatable dispose will the delete the column and free the memory.
col.Dispose()
col = Nothing

col = New DataColumn
col.Caption = "Name"
'Datatype will set the datatype for the particular column
col.DataType = System.Type.GetType("System.String")
dt.Columns.Add(col)
col.Dispose()
col = Nothing

col = New DataColumn
col.Caption = "Address"
col.DataType = System.Type.GetType("System.String")
dt.Columns.Add(col)
col.Dispose()
col = Nothing

'To show headings of the columns
Dim i As Integer
For i = 1 To dt.Columns.Count - 1
System.Console.Write(dt.Columns.Item(i).Caption)
' ControlChars.Tab will give the gap of one tab.
System.Console.Write(ControlChars.Tab)

Next

System.Console.WriteLine()
'To insert data in the virtual table

For i = 1 To 10
row = dt.NewRow
row.Item(1) = "ABC" & i
row.Item(2) = "XYZ" & i
dt.Rows.Add(row)

Next
Dim j As Integer
'Outer loop is used for the rows.
For i = 0 To dt.Rows.Count - 1
'Innser loop is used for the columns.
For j = 0 To dt.Columns.Count - 1
System.Console.Write(dt.Rows(i).Item(j))
System.Console.Write(ControlChars.Tab)
Next
System.Console.WriteLine()
Next
End Sub

End Module



Hope it will help u.
regards
Neetu



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Creating Virtual table using vb.net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Shell & Shell wait Command in VB
Previous Resource: Vb.Net control horizontal scorll bar
Return to Discussion Resource Index
Post New Resource
Category: VB.NET Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use