Saturday, August 27, 2011

Creating a temporary table in vb.net and binding to a gridview

This is a example that how to create temporary table in  vb.net

**************************
Imports System.Data



Partial Class _Default
    Inherits System.Web.UI.Page
    Public table1 As DataTable
    Public ds As DataSet

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        table()

    End Sub
    Public Function table()
        Try
            table1 = New DataTable
            table1.Columns.Add("rollno", Type.GetType("System.Int32"))
            table1.Columns.Add("name", Type.GetType("System.String"))
            table1.Columns.Add("result", Type.GetType("System.String"))

            Dim editrow As DataRow
            editrow = table1.NewRow
            editrow(0) = 41
            editrow(1) = "lalit kumar"
            editrow(2) = "Pass"
            table1.Rows.Add(editrow)
            ds = New DataSet
            ds.Tables.Add(table1)
            GridView1.DataSource = ds
            GridView1.DataBind()

        Catch ex As Exception
            Response.Write(ex.Message)

        End Try
    End Function
End Class

****************************

No comments:

Post a Comment