• 0

[ASP.NET] Populate data to Datagrid


Question

(About web application)

How to do to search some information and show in a Datagrid? what is the coding?

I'm using M-Access database.

what is the problem for this code?

Dim ds As New DataSet

Dim sql As String = "SELECT SMT_date, SMT_newssort, SMT_title FROM STM_news"

Dim adpt As New OleDb.OleDbDataAdapter(sql, OleDbConnection1)

adpt.Fill(ds)

DataGrid1.DataSource = ds.Tables("STM_news")

DataGrid1.DataBind()

Please help me! Thanks a lot.

Link to comment
https://www.neowin.net/forum/topic/487002-aspnet-populate-data-to-datagrid/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

You haven't named the table, so trying to access it in the Tables collection by name won't work. If you just bind to the dataset, you'll be ok. The datagrid will use the DefaultView.

' DataGrid1.DataSource = ds.Tables("STM_news")
DataGrid1.DataSource = ds
DataGrid1.DataBind()

  • 0
  weenur said:

You haven't named the table, so trying to access it in the Tables collection by name won't work. If you just bind to the dataset, you'll be ok. The datagrid will use the DefaultView.

' DataGrid1.DataSource = ds.Tables("STM_news")
DataGrid1.DataSource = ds
DataGrid1.DataBind()

Sorry, it doesn't work. I have tried so many ways, some like you say the DefaultView, under the windows application it works, but under web application doesn't work.

I don't know what's the problem.

  • 0
  ollie said:

Sorry, it doesn't work. I have tried so many ways, some like you say the DefaultView, under the windows application it works, but under web application doesn't work.

I don't know what's the problem.

Debug and ensure that you're actually returning data. Try writing out the Rows.Count or something to ensure that you are indeed getting a row set back.

  • 0
  weenur said:

Debug and ensure that you're actually returning data. Try writing out the Rows.Count or something to ensure that you are indeed getting a row set back.

Really, thanks a lot for reply me.

I have tried this, I'm sure that some data returning, from the msg it shows there were some rows returned.

but this is nothing in the Datagrid.

help me please..........

  • 0
  ollie said:

Really, thanks a lot for reply me.

I have tried this, I'm sure that some data returning, from the msg it shows there were some rows returned.

but this is nothing in the Datagrid.

help me please..........

Could you post the aspx and vb file, if necessary, so I can look at your grid properties? Just zip 'em up and attach 'em to your post.

  • 0
  ollie said:

Hi, weenur, here are the aspx and vb file.

You're using 2003, aren't you? I no longer have it installed. :pinch:

I think your problem is that you've defined the data source in the designer, and it's overriding your code. Are you getting any data bound to the grid before your button click?

  • 0
  weenur said:

You're using 2003, aren't you? I no longer have it installed. :pinch:

I think your problem is that you've defined the data source in the designer, and it's overriding your code. Are you getting any data bound to the grid before your button click?

Yes, I'm using 2003. and there are some data bound to the grid before button click, any problem?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.