ARTICLE

Display data using DataAdapter of disconnected model

Posted by Sapna Articles | ADO.NET in VB.NET July 19, 2011
DataAdapter enable data transfer from physical database to in memory database and back again.
Download Files:
 
Reader Level:

In my previous articles I have used connected model. In that I have used SqlConnection, SqlCommand and SqlDataReader object to connect to database and retrieve data. in this article I am going to use disconnected model. In disconnected model, you don't need to keep a connection to the database open. In disconnected model. You need to use DataAdapter, DataTable, DataView and DataSet.
DataAdapter: DataAdapter enable data transfer from physical database to in memory database and back again.
In this article I am using DataAdapter to show you how its work.
 

Web.config

<?xml version="1.0"?>
<
configuration>
  <
connectionStrings>
    <
add name="Employee" connectionString="Data Source=Sapna-PC\Sapna;Initial Catalog=master;User ID=sa;Password=SapnaBeniwal" providerName="System.Data.SqlClient"/>
  </
connectionStrings>
    <
system.web>
        <
compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
    </
system.web>
</
configuration>

App_Code/Employee.vb

Imports
Microsoft.VisualBasic
Imports
System.Data
Imports
System.Data.SqlClient
Imports
System.Web.Configuration
Public
Class Employee
    Public Shared ReadOnly Connection_String As String
    Public Function All_Detail() As DataTable
        Dim sda As New SqlDataAdapter("Select * from Employee", Connection_String)
        'creata a DataTable
        Dim dt As New DataTable()
        sda.Fill(dt)
        Return dt
    End Function
    Shared Sub New()
        Connection_String = WebConfigurationManager.ConnectionStrings("Employee").ConnectionString
    End Sub

End
Class


 Default.aspx

<%
@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
    <title></title>

</
head>
<
body>
    <form id="form1" runat="server">
   <div>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1">
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" TypeName="Employee" SelectMethod="All_Detail" runat="server"></asp:ObjectDataSource>
    </div>
    </form>

</
body>
</
html>

 
Output:

DataAdapter.gif


Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor