Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
I am using C# windows application
Here I am not taking data grid view from ToolBox But I am trying to do this as run time Below the code
C#
public partial class Form1 : Form
    {
        DataGridView dataGrid;
        DataSet dataSet;        
        OleDbDataAdapter da;       
        private OleDbConnection conn = new OleDbConnection();        
        private string conStr = "Provider=SQLOLEDB;Data Source=SERVICE\\SQLEXPRESS;Initial Catalog=Test;Integrated Security=SSPI";
        public Form1()
        {
            InitializeComponent();
            conn = new OleDbConnection(conStr);
            conn.Open();
            InitializeComponent();
            //CreateGridAndButton();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            string str = "SP_TestForAccess";
            OleDbCommand cmd = new OleDbCommand();
            cmd = new OleDbCommand(str, conn);
            dataGrid=new DataGridView();
            da = new OleDbDataAdapter();
            DataTable dt = new DataTable();
            dataSet = new DataSet();
            da.SelectCommand = cmd;
            //dt.Load(dr);
            //dataSet.Tables.Add(dt);
            da.Fill(dataSet, "tbl_main");
            dataGrid.DataSource = dataSet.Tables[0].DefaultView;            
        }        
    }

in Data set it shows the data but after run in the windows form Data grid view does not show any thing.
why it is happening like this

Thanks to All
Posted
Updated 7-Aug-12 5:42am
v2

1 solution

Just try this.

C#
dataGrid.DataSource = dataSet.Tables[0];


Also Did You add the datagridview to the page controls..

Something like.

C#
this.Controls.Add(dataGrid);
 
Share this answer
 
v2
Comments
IndrajitDasgupat 7-Aug-12 7:04am    
I tried but it is Not comming
Santhosh Kumar Jayaraman 7-Aug-12 7:06am    
updated the solution.

this.Controls.Add(dataGrid);
IndrajitDasgupat 7-Aug-12 7:14am    
Yes Sir, it is working now but data grid view is coming very small size I want to make it bigger in run time is it possible
Santhosh Kumar Jayaraman 7-Aug-12 7:46am    
You have to set datagrid.Width and datagrid.Height properties to some value.

Mark this answer as accepted if it is resolved

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