• 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

    • Hello, I have had good results with Corsair, Crucial, Kioxia (formerly Toshiba), Nextorage, OWC, Patriot, Sabrent, Samsung, SanDisk (formerly Western Digital), Solidigm (formerly Intel) and Team Group SSDs.  Be sure to look at warranty length, and whether the drive uses TLC or QLC memory.  The former tends to be faster and lasts longer, but QLC is maturing and is usually less expensive.   Regards, Aryeh Goretsky  
    • Today's Windows 11 Preview Update (KB5062660) (26100.4770) was a pain in the royal butt. 1. It shut down one of my W11 devices during the update. I had to do a cold boot. The update then finished. 2. It rolled back the network adapter to April on both of my W11 devices. I updated the adapter to the June release, which promptly broke my internet connection. 3. I had to reboot my router and then restart both devices to get my internet connection back. There was one good thing about today's update. My utility software was finally able to update Notepad after several failed attempts before today's update. Anyway, all now appears GTG. Thank goodness.
    • Windows 11 receives a handful of new AI features by Taras Buria Microsoft is supercharging its operating system with a handful of new AI-powered features. Those with compatible computers (mostly Copilot+ PCs) can download a new Windows 11 update that introduces new AI experiences. One of the biggest updates is the Settings app, which now features agentic search to understand complaints about your computer. You can click the search box and tell Windows what is wrong. For example, "my mouse cursor is too small." Windows will then process your request and suggest taking action on your behalf. You can also ask for specific changes like, "change my screen resolution to 1920x1080." The Settings agent is now available for users with Snapdragon-powered Copilot+ PCs. It is coming soon to Intel and AMD-based Copilot+ PCs. Click to Do has received several new actions: Practice in Reading Coach helps improve reading skills by giving feedback and offering suggestions on how to improve. Read with Immersive Reader displays text in a distraction-free environment with the ability to adjust text size, spacing, font and background theme, have text read aloud, break words into syllables and highlight parts of speech. The picture dictionary shows images for unfamiliar words. Draft with Copilot in Word turns a portion of text into a full draft. Actions in Microsoft Teams let you click an email to send a message or schedule a meeting. More AI is available in the Photos app. After a couple of months in testing, the Relight feature is now rolling out, allowing users to adjust lights with AI. You can place three light sources or use built-in presets to edit your photos. Like with the Settings app, this feature is currently available to Snapdragon-powered devices only. Paint now has a sticker generator and a new object select tool that uses AI to isolate the object and edit individual elements, even if they are part of one layer. Snipping Tool has received the "Perfect Screenshot" feature to help you select parts of the screen for a proper cropped screenshot, and a new Color Picker to read colors on the screen in different formats (available on all PCs, not only Copilot+ PCs). Finally, the Copilot app now supports Highlights, a new feature that enables Copilot to show you how to perform specific tasks in the current app on the entire desktop. Today's updates are not just about AI and sticker generation. Microsoft is also improving the performance and security of its system with a redesigned blue screen of death and the new Quick Machine Recovery system. You can read more about those changes here. If you want to get all these updates today, download the latest non-security update for Windows 11 version 24H2, which is now available.
    • Yet my Surface Pro 7+ was running ok with 23H2, only having issues with the laggy-mess that's the new File Explorer...
  • Recent Achievements

    • Week One Done
      SmileWorks Dental earned a badge
      Week One Done
    • Community Regular
      vZeroG went up a rank
      Community Regular
    • Collaborator
      Snake Doc earned a badge
      Collaborator
    • Week One Done
      Snake Doc earned a badge
      Week One Done
    • One Month Later
      Johnny Mrkvička earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      587
    2. 2
      Michael Scrip
      199
    3. 3
      ATLien_0
      192
    4. 4
      +FloatingFatMan
      129
    5. 5
      Xenon
      122
  • Tell a friend

    Love Neowin? Tell a friend!