Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2006, 08:12 AM
Authorized User
 
Join Date: Mar 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to kalchev
Default GridView populate

Hello,
I've tried to populate my gridView from a database. The program starts but Gridview1 is empty. There is something wrong with tha way I build my dataTable I think. Hope somebody can give me advice or write any kind of a solutin.
Thank You!

p.s. Fname, SecondName, Phone, Lastname are fields from my Danni.mdb. And I think exactly there I have a mistake but I am not sure and I have absolutely no idea what is the mistake :)

Here is the source:

Code:
Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString
 
            Dim connection As New OleDb.OleDbConnection(connString)
 
            Dim command As New OleDb.OleDbCommand("SELECT * from MarkaNaKola", connection)
 
            Dim adapter As New OleDb.OleDbDataAdapter(command)

            Dim authors As New DataSet()

            adapter.Fill(authors)

            If authors.Tables.Count > 0 Then

                Dim DTable As DataTable
                Dim row As DataRow
                'create a DataTable
                DTable = New DataTable
                DTable.Columns.Add(New DataColumn("FName", GetType(String)))
                DTable.Columns.Add(New DataColumn("SecondName", GetType(String)))
                DTable.Columns.Add(New DataColumn("LastName", GetType(String)))
                DTable.Columns.Add(New DataColumn("phone", GetType(String)))




                For Each row In authors.Tables(0).Rows
                    row = DTable.NewRow()
                    row(0) = row("FName").ToString()
                    row(1) = row("SecondName").ToString()
                    row(2) = row("LastName").ToString()
                    row(3) = row("phone").ToString()
                    DTable.Rows.Add(row)

 
                Next
                GridView1.Enabled = False
                GridView1.DataSource = New DataView(DTable)
                GridView1.Enabled = True
                GridView1.DataBind()
                'Dim Column As Data.DataColumn
                'For Each Column In DTable.Columns
                ' Response.Write(Column.ColumnName & "<br>")
                ' Next

            End If
 
Old April 13th, 2006, 01:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

change:
GridView1.DataSource = New DataView(DTable)
to
GridView1.DataSource = DTable


 
Old April 18th, 2006, 05:08 AM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to prameshgupta Send a message via AIM to prameshgupta
Default

Change this GridView1.DataSource = New DataView(DTable)
to GridView1.DataSource = DTable


Ramesh P





Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
GridView auto populate stonesbg ASP.NET 1.0 and 1.1 Basics 0 February 19th, 2007 10:41 AM
Populate a field Hennie Access VBA 2 September 13th, 2006 12:32 PM
populate Gridview from MSaccess data alaqunaibi ADO.NET 1 June 19th, 2006 01:25 AM
Populate Listview yves VB Databases Basics 1 February 6th, 2006 08:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.