views:

38

answers:

2

Hi,

I want to bind datagridview in windows application with dynamically changed datatable.

I have windows form with two textboxes, one for connection string with sql server and the other for sql query string. I just want to display data in datagridview in order to see data. I don't need anything fancy, just to read result of sql query.

Thanks in advance!

DP

+2  A: 

Just assign the DataTable to the Datasource property of the DataGridView.

leppie
I did that, but I got an empty datagridview even if dataTable has 1 row. :(
Deveti Putnik
Did you disable `AutoGenerateColumns` maybe?
leppie
You are right... :) Thank yo very much!
Deveti Putnik
A: 

Once you have the datatable just do the following:

myDataGrid.DataSource = myDataTable;
myDataGrid.DataBind();

That should be all you need to do.

Giles
Bzzzz, that is ASP.NET code, not Winforms. ;P
leppie
leppie was right. I need Winforms solution.
Deveti Putnik