SqlCommand cmd = new SqlCommand("Select sur_accounttype from tsys_user",conSQL ) ;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"tsys_user");
dataGridView1.DataSource = ds;
ds.Dispose();
            Asked
            
        
        
            Active
            
        
            Viewed 327 times
        
    3 Answers
2
            
            
        Remove this from your code
ds.Dispose();
ds.Dispose actually doesn't do anything. The problem is with specifying the datasource to a table in the dataset.
dataGridView1.DataSource = ds.Tables[0].DefaultView;
- 
                    @odlanyer, try `dataGridView1.DataSource = ds.Tables[0]` – Habib Jul 18 '12 at 09:13
- 
                    Yups it makes a [no difference](http://stackoverflow.com/questions/913228/should-i-dispose-dataset-and-datatable) – V4Vendetta Jul 18 '12 at 09:14
- 
                    @habib, tnx for your time, I appreciate it. – odlan yer Jul 18 '12 at 09:16
- 
                    @V4Vendetta, thanks, your link is something totally new to me , thanks again – Habib Jul 18 '12 at 09:16
- 
                    1@Habib Actually your answer made me ponder why would it be an issue and SO didn't disappoint me, guess we both learned something good :) – V4Vendetta Jul 18 '12 at 09:20
1
            Try to set DataMember property.
dataGridView1.DataSource = ds;
dataGridView1.DataMember="tsys_user";
Or create a DataTable and populate it.
DataTable dt=new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
 
    
    
        KV Prajapati
        
- 93,659
- 19
- 148
- 186
0
            
            
        You are disposing your dataset right after you have added it to your grid
 
    
    
        JohnnBlade
        
- 4,261
- 1
- 21
- 22
 
     
    