Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to execute SQL Query inside DataSet?

How to execute SQL Query inside DataSet?

Scheduled Pinned Locked Moved Visual Basic
databasequestionxmltutorialannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    slam Iqbal
    wrote on last edited by
    #1

    I want to execute SQL Query within a Dataset. I don't know how it should be done. I just have some sample Query & sample data.

    'test.xml file Contains 3 columns:
    'ID, Name, Location
    'Sample Values:
    ''ID, Name, Location
    ''1, abc, loca
    ''2, ijk, locb
    ''3, xyz, locc
    ''4, uvw, locd
    Dim ds As New DataSet
    ds.ReadXml("test.xml")

        'Sql Query is: "Select Name fom ??? where ID=1"
        'Is this possible to to retrive the output of that Sql query from test.xml using DataSet? 
        'If DataSet does not support this type of operation then how can I execute that or any other query?
    

    Here Is the test.xml File:

    <?xml version="1.0" standalone="yes"?>
    <DataSetSchema>
    <Tab1>
    <ID>1</ID>
    <Name>abc</Name>
    <Location>loca</Location>
    </Tab1>
    <Tab1>
    <ID>2</ID>
    <Name>ijk</Name>
    <Location>locb</Location>
    </Tab1>
    <Tab1>
    <ID>3</ID>
    <Name>xyz</Name>
    <Location>locc</Location>
    </Tab1>
    <Tab1>
    <ID>4</ID>
    <Name>uvw</Name>
    <Location>locd</Location>
    </Tab1>
    </DataSetSchema>

    W 1 Reply Last reply
    0
    • S slam Iqbal

      I want to execute SQL Query within a Dataset. I don't know how it should be done. I just have some sample Query & sample data.

      'test.xml file Contains 3 columns:
      'ID, Name, Location
      'Sample Values:
      ''ID, Name, Location
      ''1, abc, loca
      ''2, ijk, locb
      ''3, xyz, locc
      ''4, uvw, locd
      Dim ds As New DataSet
      ds.ReadXml("test.xml")

          'Sql Query is: "Select Name fom ??? where ID=1"
          'Is this possible to to retrive the output of that Sql query from test.xml using DataSet? 
          'If DataSet does not support this type of operation then how can I execute that or any other query?
      

      Here Is the test.xml File:

      <?xml version="1.0" standalone="yes"?>
      <DataSetSchema>
      <Tab1>
      <ID>1</ID>
      <Name>abc</Name>
      <Location>loca</Location>
      </Tab1>
      <Tab1>
      <ID>2</ID>
      <Name>ijk</Name>
      <Location>locb</Location>
      </Tab1>
      <Tab1>
      <ID>3</ID>
      <Name>xyz</Name>
      <Location>locc</Location>
      </Tab1>
      <Tab1>
      <ID>4</ID>
      <Name>uvw</Name>
      <Location>locd</Location>
      </Tab1>
      </DataSetSchema>

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      A dataset returns a collection of DataTables, in this case it would only contain one Table. I don't think it is possible to query DataSets using SQL. You would need to iterate through the table until you found an ID matching 1 and retrieve the name. Personally I prefer to use XML literals and LinQ to retrieve data from xml files like this

      Dim datatest As XDocument = XDocument.Load("Test.xml")
      For Each student In From element In datatest...<Tab1>
      If student...<ID>.Value = 1 Then
      name = student...<Name>.Value
      Exit For
      End If
      Next
      MsgBox(Name)

      That makes everything very concise and readable. Hope this helps. Happy Coding

      S 1 Reply Last reply
      0
      • W Wayne Gaylard

        A dataset returns a collection of DataTables, in this case it would only contain one Table. I don't think it is possible to query DataSets using SQL. You would need to iterate through the table until you found an ID matching 1 and retrieve the name. Personally I prefer to use XML literals and LinQ to retrieve data from xml files like this

        Dim datatest As XDocument = XDocument.Load("Test.xml")
        For Each student In From element In datatest...<Tab1>
        If student...<ID>.Value = 1 Then
        name = student...<Name>.Value
        Exit For
        End If
        Next
        MsgBox(Name)

        That makes everything very concise and readable. Hope this helps. Happy Coding

        S Offline
        S Offline
        slam Iqbal
        wrote on last edited by
        #3

        Is that only one way to do quering a dataset? I tried Dataset.Select("ID=1") but it is not enought for my requirement. anyway thanks.

        D 1 Reply Last reply
        0
        • S slam Iqbal

          Is that only one way to do quering a dataset? I tried Dataset.Select("ID=1") but it is not enought for my requirement. anyway thanks.

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #4

          You could always bind the data to a bunch of controls e.g. bindingsource, bindingnavigator and datagridview and then use the FILTER property of the BindingSource, as it acts just like a 'where' clause in SQL.

          Dave Don't forget to rate messages!
          Find Me On: Web|Facebook|Twitter|LinkedIn
          Waving? dave.m.auld[at]googlewave.com

          modified on Thursday, July 15, 2010 10:10 AM

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups