Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Displaying data in a gridview programatically

Displaying data in a gridview programatically

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    solarthur01
    wrote on last edited by
    #1

    I am trying to display some data from a database withing a gridview. Using a few books, i have managed to display the data in a msngbox but im having problmes displaying it on the asp webpage. Heres what i have at the moment: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myconnection As OleDbConnection myconnection = New OleDbConnection() Dim connectionString As String = "provider=Microsoft.Jet.OLEDB.4.0;" + _ "data source = C:\Documents and Settings\admin2\My Documents\glaxodata.mdb" myconnection.ConnectionString = connectionString Dim mycommand As OleDbCommand mycommand = New OleDbCommand("select * from glaxoAll5032007OrderDetail", myconnection) Dim myreader As OleDbDataReader myconnection.Open() myreader = mycommand.ExecuteReader() myreader.Read() Dim newrow As DataRow MsgBox(myreader("Field1")) Dim mytable As DataTable mytable = New DataTable() mytable.Rows.Add(newrow) MsgBox(mytable.Rows.Count) mytable.Rows.Add() GridView1.DataSource = mytable myconnection.Close() End Sub can any1 help?

    U 1 Reply Last reply
    0
    • S solarthur01

      I am trying to display some data from a database withing a gridview. Using a few books, i have managed to display the data in a msngbox but im having problmes displaying it on the asp webpage. Heres what i have at the moment: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myconnection As OleDbConnection myconnection = New OleDbConnection() Dim connectionString As String = "provider=Microsoft.Jet.OLEDB.4.0;" + _ "data source = C:\Documents and Settings\admin2\My Documents\glaxodata.mdb" myconnection.ConnectionString = connectionString Dim mycommand As OleDbCommand mycommand = New OleDbCommand("select * from glaxoAll5032007OrderDetail", myconnection) Dim myreader As OleDbDataReader myconnection.Open() myreader = mycommand.ExecuteReader() myreader.Read() Dim newrow As DataRow MsgBox(myreader("Field1")) Dim mytable As DataTable mytable = New DataTable() mytable.Rows.Add(newrow) MsgBox(mytable.Rows.Count) mytable.Rows.Add() GridView1.DataSource = mytable myconnection.Close() End Sub can any1 help?

      U Offline
      U Offline
      Usharva
      wrote on last edited by
      #2

      Hi! I dint understand why you are using ExecuteReader? It returns single record right? If you want to bind more than one record get data to datatable directly and bind to the gridview 'GridView1.DataSource = mytable' after this line add the following line 'GridView1.databind()'

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups