views:

40

answers:

3

I need to know how to display the result of a select query in a datagrid or GridView with VB.NET?

Consider SELECT * FROM some_table. I don't know what columns the table has. Is there a way to just output the result to a table, with a dataset for example?

How can this be done easily?

+1  A: 

Use SQLDataSource control to begin with. Click on its Smart Task handle. It's pretty straightforward to configure. set your datagrid's datasource to SQLDataSourceControl via your datagrid's Smart Task handle. Fire up your site and you'll see the result in your datagrid control.

Kamyar
+1  A: 

Consider using 2 components:

  • SqlDataSource
  • GridView

Find both those in your webpage's Design view toolbox. Double click each to have them show up on your webform.

Your SQLDataSource will ask your for "SELECT" command. Paste in any SELECT statement, and you can preview the results. Better yet, create a stored procedure in SQL Server, and use it instead of an ad-hoc SQL statement.

Your GridView will, by default, have AutoGenerateColumns=True. This will ensure that your resultset from your SQLDataSource will have the columns named exactly on the GridView.

alt text

alt text

alt text

This article has some guidance and instructions: GridView control in ASP.NET

p.campbell
Thanks, but I used a DataSet instead!
Trikks
A: 

I found a way to do it

I created a DataSet and filled it

    Dim ds As DataSet = New DataSet()
    adapter.Fill(ds, strList)
    dataGridView1.DataSource = ds
    dataGridView1.DataBind()

And displayed it with

<asp:DataGrid ID="dataGridView1" runat="server" />
Trikks