Access DB DataAdapter To Gridview
Get 5 Hours of FREE PREMIUM Videos:
LearnVisualStudio.NET Free Preview
“ I am a lifetime member of LearnVisualStudio.net and a Premium Plus member of dotNetVideos.net.
LearnVisualStudio.net is awesome because it grows in value each year as more videos are added.
dotNetVideos.net is also great because it focuses a lot on MS Certifications and practical interview questions.
”
- Wade Harvey (IdealProgrammer.com)
Access DB DataAdapter To Gridview
Purpose: – Illustrates using Acces DB DataAdapter Gridview in VB.NET ASP.NET.
Prerequistes:
- Install Visual Web Developer 2010
- Install SQL Server Express
- Download Northwind and Pubs Databases
- Attach Northwind Database to Databases in Sql Express
- Attach pubs Database to Databases in Sql Express
Notes:
- You can build your own library of syntax examples by using same web site over and over and just add new web forms to it.
- This example uses MS Access 2010 to create the Contacts DB
Instructions:
- Use Visual Web Developer 2010
- Create new web site;
- Click File/New Web Site
- Select ASP.NET Website Template
- Select Visual Basic for Language
- name of Web Site could be VBNET_ASPNET_Syntax.
- Add New folder named "Database_ADONET"
- Right-click project name in solution explorer;
- add new folder;
- name of folder could be: Database_ADONET
- Add Web Form Named AccessDBDataAdapterToGridview to Database_ADONET folder
- Right-click Database_ADONET folder;
- add new item;
- Select Web Form
- Check place code behind in separate file
- Web Form name could be AccessDBDataAdapterToGridview
- Click on copy code in code below to copy code into web form AccessDBDataAdapterToGridview.aspx
- Click on copy code in second set of code below to copy code into code-behind AccessDBDataAdapterToGridview.aspx.vb
- Right-click on AccessDBDataAdapterToGridview.aspx in solution explorer and select view in browser
Step 1: Click on Copy Code to Cut-n-paste code into AccessDBDataAdapterToGridview.aspx
| XML | | copy code | | ? |
< %@ Page Language="VB" AutoEventWireup="false" CodeFile="AccessDBDataAdapterToGridview.aspx.vb" Inherits="ADONET_AccessDBDataAdapterToGridview" %> |
< !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> |
<h2>Populate Gridview1 with DataAdapter</h2> |
<asp:gridview ID="GridView1" runat="server"> |
</asp:gridview> |
</div> |
</form> |
</body> |
</html> |
Step 2: Click on Copy Code to Cut-n-paste code into AccessDBDataAdapterToGridview.aspx.vb
| Visual Basic | | copy code | | ? |
Imports System.Data |
Imports System.Data.OleDb |
Partial Class ADONET_AccessDBDataAdapterToGridview |
Inherits System.Web.UI.Page |
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
' create a connection string |
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Contacts.accdb" |
Dim myConnection As OleDbConnection = New OleDbConnection |
myConnection.ConnectionString = connString |
' create a data adapter |
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Contacts", myConnection) |
' create a new dataset |
Dim ds As DataSet = New DataSet |
' fill dataset |
da.Fill(ds, "Contacts") |
' write dataset contents to an xml file by calling WriteXml method |
' Attach DataSet to DataGrid |
GridView1.DataSource = ds |
GridView1.DataBind() |
End Sub |
End Class |
Step 3: Click on Copy Code to Cut-n-paste code into web.config right after the appSettings section
| XML | | copy code | | ? |
<connectionstrings> |
<add name="Northwind_ConnectionString" |
connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI" /> |
<add name="Pubs_ConnectionString" |
connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=pubs;Integrated Security=SSPI" /> |
</connectionstrings> |
Related posts:
- VB.NET ASP.NET Sql Command Select Statement Source Code Example VB.NET ASP.NET Sql Command Select Statement Source Code Example that...
- C# ASP.NET Sql Command Select Statement Source Code Example C# ASP.NET Sql Command Select Statement Source Code Example using...
- VB.NET ASP.NET Sql Command Delete Statement Source Code Example VB.NET ASP.NET Sql Command Delete Statement Source Code Example...
- VB.NET ASP.NET Sql Command Insert Statement Source Code Example VB.NET ASP.NET Sql Command Insert Statement Source Code Example...
- VB.NET ASP.NET Sql Command Update Statement Source Code Example VB.NET ASP.NET Sql Command Update Statement Source Code Example...
Related posts brought to you by Yet Another Related Posts Plugin.














































hi there,
even i tried this but the da.fill() is not working its showing some exception ………..so what should i do?