Thread: query result doesn't appear in datagrid

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    query result doesn't appear in datagrid

    Hello,

    I've written the following code to show a query result in a datagrid, but I get an empty datagrid after the code is run!
    Could you please tell me how I can fix the problem?
    Do I need to assign the values to each row in the datagrind row by row using a loop?

    Code:
    OleDbConnection DBConnection = new System.Data.OleDb.OleDbConnection();
                
                DBConnection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Chakaveh\Desktop\datagridTest\test1\dgt.accdb";
    
                string SQL = "SELECT * FROM dgtest";
    
                OleDbCommand cmd = new OleDbCommand(SQL,DBConnection);
    
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    
                DataSet ds = new DataSet();
    
                da.Fill(ds);
    
                DataTable entries = ds.Tables[0];
    
                dataGridView1.ReadOnly = true; 
    
                dataGridView1.DataSource = entries;
    
                cmd.Dispose();
    
                DBConnection.Close();
    thank you
    Last edited by arian; 07-28-2015 at 12:53 PM.

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    I had made a mistake adding 2 columns to the datagrid at the beginning
    The result was shown after the columns and I wasn't paying attention to the scrol
    The code is perfectly running

    Arian

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I test for a result, but any result over 1 fails
    By jeremy duncan in forum C++ Programming
    Replies: 10
    Last Post: 05-23-2012, 01:23 PM
  2. It doesn't return a correct result...
    By pantera in forum C++ Programming
    Replies: 5
    Last Post: 01-16-2010, 05:23 PM
  3. query result
    By Leite33 in forum Windows Programming
    Replies: 5
    Last Post: 01-07-2007, 01:55 AM
  4. Datagrid row by row
    By Leite33 in forum C++ Programming
    Replies: 0
    Last Post: 09-12-2006, 01:17 PM
  5. Datagrid Events
    By gvector1 in forum C# Programming
    Replies: 0
    Last Post: 10-01-2003, 09:43 AM