This tutorial will show you how to create data table without SQL server in ASP.NET and VB.NET 2.0. This is very useful for storing temporary data.
Add a GridView control, two lable controls, three textbox controls and button control in the page
Create datatable structure.
|
Private Function CreateDataTable() As DataTable
Dim myDataTable As DataTable = New DataTable()
Dim myDataColumn As DataColumn
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "id"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "username"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "firstname"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "lastname"
myDataTable.Columns.Add(myDataColumn)
Return myDataTable
End Function |
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
Insert data into datatable.
|
Private Function AddDataToTable(ByVal username As String, ByVal firstname As String, ByVal lastname As String, ByVal myTable As DataTable)
Dim row As DataRow
row = myTable.NewRow()
row("id") = Guid.NewGuid().ToString()
row("username") = username
row("firstname") = firstname
row("lastname") = lastname
myTable.Rows.Add(row)
End Function
|
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
Add data to datatable which we have created
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If txtUserName.Text.Trim() = "" Then
Me.lblTips.Text = "You must fill a username."
Return
Else
AddDataToTable(Me.txtUserName.Text.Trim(), Me.txtFirstName.Text.Trim(), Me.txtLastName.Text.Trim(), CType(Session("myDatatable"), DataTable))
Me.GridView1.DataSource = CType(Session("myDatatable"), DataTable).DefaultView
Me.GridView1.DataBind()
Me.txtFirstName.Text = ""
Me.txtLastName.Text = ""
Me.txtUserName.Text = ""
Me.lblTips.Text = ""
End If
End Sub
|
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
Be noted "Session["myDatatable"] = myDt;" is important to ensure we can add new data continually until the page be closed.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
myDt = New DataTable()
myDt = CreateDataTable()
Session("myDatatable") = myDt
Me.GridView1.DataSource = (CType(Session("myDatatable"), DataTable)).DefaultView
Me.GridView1.DataBind()
End If
End Sub
|
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!