Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a web form in ASP.NET using c#. By using this query:
SQL
SELECT INST_ID, LongName FROM TableCOCINSE
EXCEPT
SELECT INST_ID, LongName from TableAFTE where AFTEYR = 2016


I am trying to display the results into a GridView. This is what I have as my code:

C#
SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassoneConnectionString"].ConnectionString);
            con3.Open();

            SqlCommand com = new SqlCommand("(SELECT INST_ID, LongName FROM TableCOCINSE) EXCEPT (SELECT INST_ID, LongName FROM TableAFTE)", con3);

            DataTable dt = new DataTable();

            SqlDataReader sqlDataReader = com.ExecuteReader();

            dt.Load(sqlDataReader);
            sqlDataReader.Close();

            GridView dataGridView4 = new GridView();
            dataGridView4.DataSource = dt;



What am I missing?

What I have tried:

I have tried almost everything. The SQL Query works in SQL Server Management Studio.
Posted
Updated 23-Jun-17 8:52am

1 solution

add below line after this -> dataGridView4.DataSource = dt;

dataGridView4.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900