Solved

Gridview data error

Posted on 2013-10-30
2
750 Views
Last Modified: 2013-10-31
In vs 2010, I have a simple form to utilize data reader to display some data via a gridview control. I am getting the following:
Error	1	'System.Windows.Forms.DataGridView' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Forms.DataGridView' could be found (are you missing a using directive or an assembly reference?)	

Open in new window

The code in this form is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;

namespace ado01_Connection
{
    public partial class Form08 : Form
    {
        String cs = ConfigurationManager.ConnectionStrings["csDatabase"].ConnectionString;
        SqlConnection con = new SqlConnection();

        public Form08()
        {
            InitializeComponent();
        }

        private void Form08_Load(object sender, EventArgs e)
        {
            using (con)
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("SELECT *  FROM Customers", con);
                SqlDataReader rdr = cmd.ExecuteReader();
                BindingSource source = new BindingSource();
                //source.DataSource = rdr;
                dataGridView1.DataSource = rdr;
                dataGridView1.DataBind();
                // https://www.youtube.com/watch?v=EzwBuqILfds <-- using this link
            }
        }
    }
}

Open in new window

The error occurs at line 34:     dataGridView1.DataBind();  

This sample video is done for asp.net but I am trying to do this for c# in vs 2010 win application.

Thank you.
0
Comment
Question by:Mike Eghtebas
[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
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39611638
Remove this line of code.

dataGridView1.DataBind();

Open in new window


It is only used in Web applications.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 39613311
rhx
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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