I've just added a data source to my
project. In the book I follow, it says that I
should be able to drag a table from the data sources window and drop
it onto a form. This would create a control for each field of the
table. I want to create datagrid view control.The problem is,when I drag it, nothing appears in the form design.
it shows circle with slash while dragging.
I am using microsoft visual c# 2010 express.

5 Years
Discussion Span
Last Post by Mitja Bonca

This book you are using, uses some strange expressions. It should be written like:
Create a dataTable, then do an sql query to fill this table up, and bind it to the dataGridView.
In the code this would look like:

DataTable table;

        private void GetData()  //call this method when ever you want to populate dgv!
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
                //get data from dataBase:
                string sqlQuery = @"SELECT * FROM MyTable"; //use your own sql query!!!
                SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn);
                //if you need any parameter for the sqlCommand you do:
                //cmd.Parameters.Add("@paramName", SqlDbType.Int).Value = "Some value";
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                table = new DataTable("MyTable");

                //fill table with sql inquery:

            //set dataTable as a binding source to the dgv:
            dataGridView1.DataSource = new BindingSource(table, null);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.