Solved

Example of binding a gridview to dataset

Posted on 2007-03-26
7
2,776 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
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:zeroxp
Comment Utility
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
Comment Utility
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
Comment Utility

Thank you both. Is there a performace benefit to using a tableadapter? Why would i want to use it??
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 7

Author Comment

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

Expert Comment

by:zeroxp
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now