DataGrid --- Showing SQL Columns

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harry Whitehouse

    #1

    DataGrid --- Showing SQL Columns

    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(myQu ery);

    myCommand.Conne ction=sqlConnec tion1;

    SqlDataAdapter da = new SqlDataAdapter( myQuery, sqlConnection1) ;

    DataSet ds = new DataSet();

    da.Fill(ds,tabl ename.ToString( ));

    dataGrid1.DataS ource=ds;

    dataGrid1.Expan d(-1);


  • Greg Ewing [MVP]

    #2
    Re: DataGrid --- Showing SQL Columns

    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 Ewing [MVP]
    IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.


    "Harry Whitehouse" <harry@envmgr.c om> wrote in message
    news:euwZvYfhDH A.1952@TK2MSFTN GP10.phx.gbl...[color=blue]
    > 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[/color]
    name[color=blue]
    > 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[/color]
    table[color=blue]
    > name?
    >
    > TIA
    >
    > Harry
    >
    >
    >
    >
    >
    > String myQuery = "select * from syscolumns where id = object_id('" +
    > dbname.ToString () +
    >
    > ".." + tablename + "')";
    >
    > SqlCommand myCommand = new SqlCommand(myQu ery);
    >
    > myCommand.Conne ction=sqlConnec tion1;
    >
    > SqlDataAdapter da = new SqlDataAdapter( myQuery, sqlConnection1) ;
    >
    > DataSet ds = new DataSet();
    >
    > da.Fill(ds,tabl ename.ToString( ));
    >
    > dataGrid1.DataS ource=ds;
    >
    > dataGrid1.Expan d(-1);
    >
    >[/color]


    Comment

    • Harry Whitehouse

      #3
      Re: DataGrid --- Showing SQL Columns

      Greg --

      Right you are!

      I needed this:

      dataGrid1.DataS ource=ds.Tables[tablename.ToStr ing()];
      Thanks for the assist!!

      Harry




      Comment

      Working...