473,396 Members | 1,967 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,396 software developers and data experts.

Binding dataset to gridview

hi,
I want to bind the data from the Dataset to GridView
When I run my code I get the error
The type or namespace name 'DataRows' could not be found (are you missing a using directive or an assembly reference?)
I have called the following assemblies
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Configuration;

please help.


thanks
Dec 28 '08 #1
5 23950
PRR
750 Expert 512MB
@satyabhaskar
Hi satyabhaskar,

Binding a DataSet to GridView is straight forward...Please post some sample code..
Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection("");
  2. DataSet ds = new DataSet();
  3. SqlDataAdapter da = new SqlDataAdapter("stored proc name/query", con);
  4. da.SelectCommand.CommandType = CommandType.StoredProcedure;//Text
  5.  
  6. da.Fill(ds);
  7.  
  8. gridview1.DataSource = ds;
  9. gridview1.DataBind();
  10.  
Dec 29 '08 #2
Expand|Select|Wrap|Line Numbers
  1. //connect to database via dataset & dataadapter
  2. SqlConnection con = new SqlConnection("server=localhost;Initial Catalog=databasename;uid=;pwd=;");
  3. DataSet ds = new DataSet();
  4.  SqlDataAdapter da = new SqlDataAdapter("stored proc name", con);
  5.  da.SelectCommand.CommandType = CommandType.StoredProcedure;
  6.  da.Fill(ds);
  7.  
  8.  //create gridview by code & bind dataset to it
  9.  GridView g = new GridView();
  10.  Page.Controls.Add(g);
  11.  g.DataSource = ds;
  12.  Page.DataBind();
regards

Preeti
Dec 9 '11 #3
Expand|Select|Wrap|Line Numbers
  1. if(!IsPostBack)
  2.     {
  3.  
  4.       // Declare the query string.
  5.       String queryString = 
  6.         "Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]";
  7.  
  8.       // Run the query and bind the resulting DataSet
  9.       // to the GridView control.
  10.       DataSet ds = GetData(queryString);
  11.       if (ds.Tables.Count > 0)
  12.       {
  13.         AuthorsGridView.DataSource = ds;
  14.         AuthorsGridView.DataBind();
  15.       }
  16.       else
  17.       {
  18.         Message.Text = "Unable to connect to the database.";
  19.       }
Dec 9 '11 #4
007007
1
Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection("server=localhost;Initial Catalog=databasename;uid=;pwd=;");
  2. DataSet ds = new DataSet();
  3. SqlDataAdapter da = new SqlDataAdapter("stored proc name", con);
  4. da.SelectCommand.CommandType = CommandType.StoredProcedure;
  5. da.Fill(ds);
  6.  
  7.  
  8. GridView grid = new GridView();
  9. Page.Controls.Add(grid);
  10. grid.DataSource = ds;
  11. Page.DataBind();
Dec 9 '11 #5
Frinavale
9,735 Expert Mod 8TB
007007,

Do you have a question?
The code that you have posted already exists within this thread as a part of the answer...Please clarify the reason for your posted code.

-Frinny
Dec 9 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: GrumpyDev | last post by:
Hi. My question is regarding binding a DataSet to a DataGrid. When I change Caption property of all column in my dataset and then bind dataset to a DataGrid, new caption aren't displayed in a grid...
4
by: Mike | last post by:
I'm having trouble getting a gridview to bind. I probably missing something completely obvious and would appreciate any help on offer. I'm passing parameters via querystring, and have created a...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString;...
6
by: igotyourdotnet | last post by:
I have a dataset that is populating my gridview, but I have a data in the dataset coming out like .011 and showing in the gridView as .011%. I need to calculate that so it shows as 1.1% and not...
2
by: Greg | last post by:
Hello, I am trying to bind a GridView to a custom object I have created. First, here is what I'm trying to do: I have a wizard for adding/editing Users. When the wizard begins, a User...
3
by: Lloyd Sheen | last post by:
Is there an example of VB code which will take a datasource and extract from that the needed info (columns etc.) to create the columns and then bind the data? This seems so much more difficult...
6
by: cmorgan76 | last post by:
This is a 2 part question: Part 1: I am accesing a web service that returns an xml string of user information. I am attempting to load the XML into an XMLDocument, save the document, load it...
0
by: Kirsten | last post by:
I am having trouble binding a DataSet to TextBoxes on a form. The last line gives me this error: "Child list for field tbl cannot be created" my code is this: Dim sql As String = "Select *...
0
by: sudhavamsikiran | last post by:
hi friends Please solve this issue. I have a gridview with a label and 2 textboxes as given below.but when am trying to update the textbox value its not detecting and not updating the value. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.