Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

use datareader for binding dataGridView1

Posted on 2014-04-22
8
Medium Priority
?
112 Views
Last Modified: 2014-11-30
i have a table in sql server 2008
i want to bind it using datareader
0
Comment
Question by:ajaymaster1558
[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
  • 4
  • 3
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40014719
you assign the datareader object the same way, why do you ask?
any issue? error messages?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40014721
most important point for your feedback: please keep your test/code as simple as possible as to reproduce the problem.
0
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 40014916
sample code is given below..
using (SqlCommand command = new SqlCommand("select * from YourTable", new SqlConnection("Server=.;Trusted_Connection=False;User ID=xxx;Password=xxxx;Initial Catalog=DatabaseName")))
            {
                try
                {
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    GridView1.DataSource = reader;
                    GridView1.DataBind();
                }
                catch (Exception ex)
                {
                    command.Connection.Close();
                }
                finally
                {
                    command.Connection.Close();
                }
            }
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:ajaymaster1558
ID: 40020176
SqlConnection cnsql = new SqlConnection(cnstring);
            cnsql.Open();
            string sql = "select * from sell";
            SqlCommand cmsql = new SqlCommand(sql, cnsql);
            SqlDataReader drsql = cmsql.ExecuteReader();

            dataGridView1.DataSource = drsql;

this is my code
but it's not work
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40020470
and what it's your exact error message?
0
 

Author Comment

by:ajaymaster1558
ID: 40029339
not get any error but it not show any data or any thing
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 40029348
that is another issue, for example the grid is not actually runat=server, or rebinded later with no data source ...
you will need to debug if you see any rebind after that code
0
 

Author Closing Comment

by:ajaymaster1558
ID: 40472429
thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 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