Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Bind Datagrid to Datareader

Total Hit ( 1513)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Most of times we see Datagrid Bound with Dataset but here is easy approach using Datareader

Click here to copy the following block
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

  Sub Page_Load(Sender As Object, E As EventArgs)
  
    ' TODO: Update the ConnectionString and CommandText values for your application
    Dim ConnectionString As String = "server=(local);database=pubs;trusted_connection=true"
    Dim CommandText As String = "select au_lname as [Last Name], au_fname as [First Name], Address, City, State from Authors"
  
  
    Dim myConnection As New SqlConnection(ConnectionString)
    Dim myCommand As New SqlCommand(CommandText, myConnection)
  
  
    myConnection.Open()
  
    Dim dr As SqlDataReader = myCommand.ExecuteReader()
  
    '//Bind with Dataset
    DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    DataGrid1.DataBind()
  
  End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
  <h2>Simple Data Report
  </h2>
  <hr size="1" />
  <form runat="server">
    <asp:datagrid id="DataGrid1" runat="server" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" EnableViewState="False">
      <HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
      <ItemStyle backcolor="#DEDFDE"></ItemStyle>
    </asp:datagrid>
  </form>
</body>
</html>


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.