Solved

Example of binding a gridview to dataset

Posted on 2007-03-26
7
2,791 Views
Last Modified: 2011-10-03
I found this example of binding a gridview to a dataset but how about if I want to use a TableAdapter?

http://www.codersource.net/asp_net_grid_view_whidbey.aspx

0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:zeroxp
ID: 18797094
after you constructed your strong typed DataSets and TableAdapters, you can use them as normal datasets or data adapters. the default adapter method name will be GetData() or Fill():

   protected void Page_Load(object sender, EventArgs e)
   {
      LoadData();
   }
   private void LoadData()
   {
      DataSet_NorthwindTableAdapters.CustomersTableAdapter tblCustomer = new DataSet_NorthwindTableAdapters.CustomersTableAdapter();
      GridView1.DataSource = tblCustomer.GetData();
      GridView1.DataBind();
      DataSet_Northwind ds = new DataSet_Northwind();
      tblCustomer.Fill(ds.Customers);
      GridView2.DataSource = ds.Customers;
      GridView2.DataBind();
   }
0
 
LVL 5

Expert Comment

by:asp_lha
ID: 18797097
maybe you can check this :

Data Binding Web Pages with a Visual Studio Data Component
http://msdn2.microsoft.com/en-us/library/3h7eexxe(VS.80).aspx

0
 
LVL 7

Author Comment

by:Camillia
ID: 18797153

Thank you both. Is there a performace benefit to using a tableadapter? Why would i want to use it??
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 7

Author Comment

by:Camillia
ID: 18797163
for example, what's the difference between the example i posted and zeroxp's example?
0
 
LVL 5

Expert Comment

by:zeroxp
ID: 18797238
i can see any performance benefit with strongly typed datasets. i'm not really sure about the performance difference. i imagine the strongly typed one perform more mapping process.
but the main benefit is you have easy and direct access to table structure. once you have the dataset configured, you can use it as a compiled class with get/update methods.
but if you just want use a simple query to access or update some record, it is still easy to use normal command, datareader, dataadapter and dataset directly.
0
 
LVL 7

Author Comment

by:Camillia
ID: 18797251
i call the stored proc, grab top 20 rows, then just want to bind to a girdview. No updatng or anything of data...
0
 
LVL 5

Accepted Solution

by:
zeroxp earned 500 total points
ID: 18797357
this is easier to me, because no need to make a dataset in the project.

      System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("SELECT TOP 20 Customers.* FROM Customers");
      using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
      {
         command.Connection = conn;
         conn.Open();
         GridView1.DataSource = command.ExecuteReader();
         GridView1.DataBind();
         conn.Close();
      }

use can also easily change to use dataadapter and dataset as your example.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question