Current location: Hot Scripts Forums » Programming Languages » ASP.NET » displaying ms access table data in gridview


displaying ms access table data in gridview

Reply
  #1 (permalink)  
Old 09-28-11, 11:28 PM
david079 david079 is offline
New Member
 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
displaying ms access table data in gridview

I have a simple windows form application in vb.net ,now I am trying to use the code in asp.net web form .I have been able to insert textbox text into ms access database table but i cannt display the gridview on web form and retrive data from the table .I have just gotten into asp.net and have tried few ways to do this but dont understand well enough.if someone could show me some code that i could add to my form i would appreciate it
Thanks



Code:
Imports System.Data.OleDb
Public Class WebForm1
    Inherits System.Web.UI.Page

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

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\testdb2.accdb")
        Dim CmdStr As String = "insert into sample (emp_name,category,city) values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
        con.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(CmdStr, con)
        cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("Done")

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\testdb2.accdb")
        Dim Query2 As String = "select * from Sample"
        Dim Da As OleDbDataAdapter, Ds As New DataSet, Dtb As New System.Data.DataTable
        con.Open()
        Da = New OleDbDataAdapter(Query2, con)
        Da.Fill(Ds)
        con.Close()
        Dtb = Ds.Tables(0)
        GridView1.DataSource = Dtb

    End Sub
End Class
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display data from mysql table divya-paru PHP 4 12-06-10 01:37 PM
how can i print the primary keys of table in ms access in php code hawkeye000 PHP 6 12-23-08 05:24 AM
From MS Excel to MS Access priyam ASP 1 09-04-08 09:50 AM
MYSQL database countll Database 2 06-19-07 04:20 PM


All times are GMT -5. The time now is 02:47 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.