?
Solved

Gridview data error

Posted on 2013-10-30
2
Medium Priority
?
775 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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

764 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