Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds am joing 3 table from database and bind that to an grid view it my task.... I done the coding but my form is no responding and struck at this line
C#
da.Fill(dt);


And my complite code is
C#
da = new SqlDataAdapter("SELECT classify21.Age, classify21.workclass, classify21.fnlwgt, classify22.maritalstatus, classify23.educationnum FROM classify21 INNER JOIN classify22 on classify21.workclass=classify22.workclass INNER JOIN classify23 on classify22.workclass = classify23.workclass",cn.con);
           dt = new DataTable();
           da.Fill(dt);
           dataGridView1.DataSource = dt;


Pls do help me Thank You...,
Posted
Updated 16-Jul-13 20:33pm
v2
Comments
Nirav Prabtani 17-Jul-13 2:39am    
has datatable contains count or not??
usha C 17-Jul-13 2:41am    
This query wrks when i execte in sql server... oly problem with binding the data in gridview i thnk...
Gautam Raithatha 17-Jul-13 2:42am    
can u please provide more details? what error actually is thrown if any? Also check that connection state is opened before executing - da.Fill(dt)
usha C 17-Jul-13 2:45am    
Am nt geting any error The form view as not responding....
praks_1 17-Jul-13 2:51am    
Check id ur dt is populauted or not then check 4 the connection and the bind

then use gridview1.databind();
 
Share this answer
 
Comments
usha C 17-Jul-13 2:53am    
No sir still same issue...
please check your sql query in backend
 
Share this answer
 
C#
using System;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
	//
	// You need to access the project's connection string here.
	//
	string connectionString ="your connection string";
	//
	// Create new SqlConnection object.
	//
	using (SqlConnection connection = new SqlConnection(connectionString))
	{
	    connection.Open();
	    //
	    // Create new SqlCommand object.
	    //
	    using (SqlCommand command = new SqlCommand("SELECT classify21.Age, classify21.workclass, classify21.fnlwgt, classify22.maritalstatus, classify23.educationnum FROM classify21 INNER JOIN classify22 on classify21.workclass=classify22.workclass INNER JOIN classify23 on classify22.workclass = classify23.workclass", connection))
	    {
		//
		// Invoke ExecuteReader method.
		//
		SqlDataReader reader = command.ExecuteReader();
		while (reader.Read())
		{

                  GridView1.DataSource=reader;
                  GridView1.DataBind();
	        }
	    }
	}
    }
}
 
Share this answer
 
v3
Comments
usha C 17-Jul-13 2:58am    
sir am using c# code here the data bind is nt supporting wat to do???
Nirav Prabtani 17-Jul-13 3:00am    
who told you that databind does not support in c#????
Nirav Prabtani 17-Jul-13 5:21am    
see updated , i have not checked it yet.
Nirav Prabtani 17-Jul-13 5:34am    
i am very sorry to say this but rohan,
this code is working check and then suggest...:)
Nirav Prabtani 17-Jul-13 5:37am    
ya but you can not say this is incorrect 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