Solved

Gridview data error

Posted on 2013-10-30
2
734 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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