473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Populate GridView with DataSet

I was using a DataView to bind records from a DB table to a DataGrid
using the following code:

Dim sqlDapter As SqlDataAdapter
Dim dSet As DataSet
Dim dView As DataView

sqlDapter = New SqlDataAdapter(strSQL, sqlConn)

dSet = New DataSet()
dView = New DataView

sqlDapter.Fill(dSet, "Users")
dView = dSet.Tables("Users").DefaultView

dgUsers.DataSource = dView
dgUsers.DataBind()

The above works fine but I did like to bind the DataGrid to a GridView
instead of a DataView as the above code shows. What I did is deleted
the DataView from the above code & added a GridView i.e. all the
instances of the DataView were replaced with GridView i.e. changed the
variable name 'dView' to 'gView' but I get this error:

Value of type 'System.Data.DataView' cannot be converted to
'System.Web.UI.WebControls.GridView'

pointing to this line

gView = dSet.Tables("Users").DefaultView

How do I populate the GridView with the DataSet?

Dec 1 '06 #1
1 24329
Your DataSet and DataView variables stay the same. You will simply set
the DataSource of the GridView to your existing dView variable.

Using what you started with...
sqlDapter.Fill(dSet, "Users")
dView = dSet.Tables("Users").DefaultView
dgUsers.DataSource = dView
dgUsers.DataBind()
Assuming the GridView is named gvUsers, make the last two lines...

gvUsers.DataSource = dView
gvUsers.DataBind()

The DataGrid and GridView both take a DataView as the DataSource.

Brennan Stehling
http://brennan.offwhite.net/blog/

rn**@rediffmail.com wrote:
I was using a DataView to bind records from a DB table to a DataGrid
using the following code:

Dim sqlDapter As SqlDataAdapter
Dim dSet As DataSet
Dim dView As DataView

sqlDapter = New SqlDataAdapter(strSQL, sqlConn)

dSet = New DataSet()
dView = New DataView

sqlDapter.Fill(dSet, "Users")
dView = dSet.Tables("Users").DefaultView

dgUsers.DataSource = dView
dgUsers.DataBind()

The above works fine but I did like to bind the DataGrid to a GridView
instead of a DataView as the above code shows. What I did is deleted
the DataView from the above code & added a GridView i.e. all the
instances of the DataView were replaced with GridView i.e. changed the
variable name 'dView' to 'gView' but I get this error:

Value of type 'System.Data.DataView' cannot be converted to
'System.Web.UI.WebControls.GridView'

pointing to this line

gView = dSet.Tables("Users").DefaultView

How do I populate the GridView with the DataSet?
Dec 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Goldsworth_Systems | last post by:
I have a string containing valid XML. How do I populate a dataset based on the string, without reference to an XML schema or writing the XML to file and reading it back in again?
7
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data...
3
by: Paul D. Fox | last post by:
I would like to read from Active Directory and populate a dataset to be passed in a Web Service. I can get the data from AD just fine, but can I populate a dataset with these values and do a...
1
by: Sachin | last post by:
Hi, I am working on ASP.Net 2.0 Beta 2 I am having problems creating crystal report using dataset I created a new dataset (DS_ExpCode) and a datatable (DT_ExpCode) under App_Code folder....
2
by: paumierj | last post by:
Hi there Here's my question : I'd like to populate a dataset from an XML string, ie: Dim sXmlString As String sXmlString = "<root type='E-Form'><question label='This is my first...
5
by: John | last post by:
Hi all, I'm sorry I'm reposting this but the original was urgent and I do need closure on this. I'm calling a stored proc which does 4 "selects" and then I populate a dataset looping through...
2
by: Thirsty Traveler | last post by:
I have an xml column in a SQL Server 2005 table that was populated with a DataSet. I would like to read that column back into a DataSet object but am not quire sure how. Any ideas?
12
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values...
1
by: elka | last post by:
I 'm going to populate a gridview with data from stored procedure in SQL server. I wrote a method which returns a dataset. than I added an object datasource with all parameters. onbutton click I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.