DataGrid --- Showing SQL Columns

  • Thread starter Thread starter Harry Whitehouse
  • Start date Start date
H

Harry Whitehouse

I have some code (below) to display the column information for a specified
SQL table. It works reasonably well, but when the grid displays it shows
the name of the table underlined and clickable. Clicking on the table name
shown in the grid expands the table to show all the rows and columns as I
want.

I realized that I needed to add the .Expand(-1) member to even show the
table name automatically. But what grid property do I set or invoke that
will just show the full table without the user having to click on the table
name?

TIA

Harry





String myQuery = "select * from syscolumns where id = object_id('" +
dbname.ToString() +

".." + tablename + "')";

SqlCommand myCommand = new SqlCommand(myQuery);

myCommand.Connection=sqlConnection1;

SqlDataAdapter da = new SqlDataAdapter(myQuery, sqlConnection1);

DataSet ds = new DataSet();

da.Fill(ds,tablename.ToString());

dataGrid1.DataSource=ds;

dataGrid1.Expand(-1);
 
Harry, you need to set the DataSource and the DataMember properties for the
grid. It sounds like you are just setting the DataSource. The DataMember
should be the table name.
 
Greg --

Right you are!

I needed this:

dataGrid1.DataSource=ds.Tables[tablename.ToString()];
Thanks for the assist!!

Harry
 
Back
Top