?
Solved

Example of binding a gridview to dataset

Posted on 2007-03-26
7
Medium Priority
?
2,801 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

743 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