开发者

display sql resultset to grid or table

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 out开发者_JAVA技巧put the result to a table, with a dataset for example?

How can this be done easily?


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.

display sql resultset to grid or table

display sql resultset to grid or table

display sql resultset to grid or table

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


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.


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜