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

x
?
Solved

Gridview data error

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

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

596 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