use datareader for binding dataGridView1

i have a table in sql server 2008
i want to bind it using datareader
ajaymaster1558Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you assign the datareader object the same way, why do you ask?
any issue? error messages?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
most important point for your feedback: please keep your test/code as simple as possible as to reproduce the problem.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
jayakrishnabhCommented:
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
 
ajaymaster1558Author Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
and what it's your exact error message?
0
 
ajaymaster1558Author Commented:
not get any error but it not show any data or any thing
0
 
ajaymaster1558Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.