data grid view
how to add values from tables to gridview using adapters and data tables
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Feb 27, 2012, 12:14 PM
To display data in gridview using adapters and data tables.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Gridview_datatable._Default" %>
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim dataTable As DataTable
Dim sqlda As SqlDataAdapter
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As New SqlConnection(strConnString)
If Not IsPostBack Then
dataTable = New DataTable()
com = New SqlCommand()
com.Connection = con
con.Open()
com.CommandText = "Select * from student"
sqlda = New SqlDataAdapter(com)
sqlda.Fill(dataTable)
con.Close()
GridView1.DataSource = dataTable
GridView1.DataMember = "student"
GridView1.DataBind()
End If
End Sub
End Class
Thanks
If this post helps you mark it as answer