Querying a DataSet object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Savas

    #1

    Querying a DataSet object

    I am new to programming in C#, but have been a VB coder for 16 years,
    and am facing a problem which I could use some help with:

    I have an XML file which I am reading into a C# DataSet object with the
    following line of code:

    ds.ReadXML(Inpu tFileName);

    Against this DataSet, I need to be able to run SQL Queries, with the
    ultimate goal of inserting (almost) all of the data in the DataSet into
    table structures on an SQL Server.

    Is there a way to execute T-SQL statements against the DataSet object?
    In particular, I need to exclude certain records based on CAST
    transformations , and then INSERT the remaining records in the DataSet
    into the server-hosted tables. I would prefer not to step through the
    records one at a time if possible.

    Any help would be appreciated.

    Thank you,
    pete




    *** Sent via Developersdex http://www.developersdex.com ***
  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: Querying a DataSet object

    Actually there are probably a half-dozen ways to skin this cat, but the one
    I'd try first is to pass your DataSet into the Update method of a
    SqlDataAdapter with a properly configured Update or Insert Command. You can
    use a stored procedure with this, and if the SQL is constructed properly,
    only the rows that you want will be inserted.
    -- Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    bogMetaFinder: http://www.blogmetafinder.com



    "Peter Savas" wrote:
    I am new to programming in C#, but have been a VB coder for 16 years,
    and am facing a problem which I could use some help with:
    >
    I have an XML file which I am reading into a C# DataSet object with the
    following line of code:
    >
    ds.ReadXML(Inpu tFileName);
    >
    Against this DataSet, I need to be able to run SQL Queries, with the
    ultimate goal of inserting (almost) all of the data in the DataSet into
    table structures on an SQL Server.
    >
    Is there a way to execute T-SQL statements against the DataSet object?
    In particular, I need to exclude certain records based on CAST
    transformations , and then INSERT the remaining records in the DataSet
    into the server-hosted tables. I would prefer not to step through the
    records one at a time if possible.
    >
    Any help would be appreciated.
    >
    Thank you,
    pete
    >
    >
    >
    >
    *** Sent via Developersdex http://www.developersdex.com ***
    >

    Comment

    • Peter Savas

      #3
      RE: Querying a DataSet object

      Peter,

      I've been trying to do as you suggested and use the SqlDataAdapter, but
      so far I've not had any luck with getting it to work. If it wouldn't be
      too much of a bother, could you give me some sample code to illustrate
      the method you're thinking of? Particularly, I really need to know how
      to load the DataAdapter's DataSet with the DataSet from the XML file.

      Thanks in advance,
      pete



      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      Working...