Solved

Gridview data error

Posted on 2013-10-30
2
694 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
2 Comments
 
LVL 62

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 33

Author Comment

by:Mike Eghtebas
ID: 39613311
rhx
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now