• 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.
  • Posts

    • many people specially intel users stick with 23h2 because for some 24h2 have degraded performance, meanwhile they took 4 years to fix ryzen performance, amd and microsoft put the work to optimize but now crippling intel. for me windows 11 it feels like a beta OS, its not stable or reliable, every patch tuesday you have to pray that they dont break something.
    • Hi all! My motherboard is Gigabyte x570 Gaming X, and believe it or not I just realised it has two M2 slots 😅 So I wanna buy a new SSD, which would mostly be used for gaming. What would you recommend I buy? Is 990 Evo Plus good choice?
    • Windows 7 its the peak of windows desktop experience, it felt polished, it was CONSISTENT, the UI was not something made to ###### people off it was more functional and productive because everything felt like a improvement. Windows 8 was horrible they did fix a little with 8.1 but the thing its that in usability it was the same as 7 you can avoid all the metro stuff, you don't need to use the cripple setting or metro stuff, for me it was bearable because it can be customized and you can make it like 7 (sure you waste time setting stuff) even if you needed a third party app. And there are serious performance improvement over 7 faster startup, Windows 10 was ok too nothing felt out of place and the start menu was usable it was filled with bloat but as usual you can remove it, what i really hated about 10 at that time it have worse windows update, you cant customize what update to install and the privacy and telemetry is horrible again it was bearable even but w11, not only they double down on things that i seriously hate on 10 like the bloat, they force changes that make no sense, make an worse start menu, worse context menu, worse task bar. force microsoft account. When i tried w10 iot enterprise LTSC on a ancient laptop, i felt that it was a throwback of what OLD windows should be a normal desktop OS with only the basics and you put the rest it was fast fluid functional, no nagging, its a productive, spend less time setting up the OS the way i want it. every windows after 7 its making it worse for me because i have to spend more time setting up
    • https://filepilot.tech/ File Pilot is a whole lot faster and offers a lot of the same features. Has a free beta available, but it looks like it's going to be a paid app in the future.
    • 24H2 was absolutely plagued with stability and compatibility problems, many of which are still not solved. You don't have to take my word for that either, given that Microsoft have an official know issues page available. Games using older versions of Easy Anti-Cheat still cause 24H2 to lock up and/or BSOD, and there's still a compatbility hold on upgrades if you have them installed as a result. Maybe 25H2 will be less of a dumpster fire, but I wouldn't count on it given Microsoft's recent track record.
  • Recent Achievements

    • Explorer
      DougQuaid went up a rank
      Explorer
    • Week One Done
      MIghty Haul earned a badge
      Week One Done
    • One Month Later
      MIghty Haul earned a badge
      One Month Later
    • Collaborator
      KD2004 earned a badge
      Collaborator
    • One Month Later
      ataho31016 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      593
    2. 2
      Michael Scrip
      200
    3. 3
      ATLien_0
      192
    4. 4
      +FloatingFatMan
      140
    5. 5
      Xenon
      127
  • Tell a friend

    Love Neowin? Tell a friend!