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. C#
  4. SQL Data Access Class and Casting DataSets

SQL Data Access Class and Casting DataSets

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 2 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.
  • B Offline
    B Offline
    blakey404
    wrote on last edited by
    #1

    I've put a SQL Data Access class together which returns a DataSet. I wanted it to be generic, therefore wrote a method to return a dataset. I am using typed datasets within my application however and the cast throws an error; MyDefinedSchemaDataSet myDS = (MyDefinedSchemaDataSet)myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName"); If i use DataAdapter.Fill on a MyDefinedSchemaDataSet.MyDefinedDataTable everything works and there are no errors, however that would throw the idea of a generic method out of the window... what to do!? :confused:

    B 1 Reply Last reply
    0
    • B blakey404

      I've put a SQL Data Access class together which returns a DataSet. I wanted it to be generic, therefore wrote a method to return a dataset. I am using typed datasets within my application however and the cast throws an error; MyDefinedSchemaDataSet myDS = (MyDefinedSchemaDataSet)myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName"); If i use DataAdapter.Fill on a MyDefinedSchemaDataSet.MyDefinedDataTable everything works and there are no errors, however that would throw the idea of a generic method out of the window... what to do!? :confused:

      B Offline
      B Offline
      Broken Bokken
      wrote on last edited by
      #2

      Try this

      DataSet utDataset = myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName");

      MyDefinedSchemaDataSet myDS = new MyDefinedSchemaDataSet();

      myDS.Load(utDataset.Tables[0].CreateDataReader(), LoadOption.OverwriteChanges, myDS.myTableName);

      Just change the values where appropriate.

      Broken Bokken You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod http://www.brokenbokken.com

      B 1 Reply Last reply
      0
      • B Broken Bokken

        Try this

        DataSet utDataset = myDataAccessClass.DoSelectStoredProcedure("procStoredProcedureName");

        MyDefinedSchemaDataSet myDS = new MyDefinedSchemaDataSet();

        myDS.Load(utDataset.Tables[0].CreateDataReader(), LoadOption.OverwriteChanges, myDS.myTableName);

        Just change the values where appropriate.

        Broken Bokken You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod http://www.brokenbokken.com

        B Offline
        B Offline
        blakey404
        wrote on last edited by
        #3

        works perfectly! thanks thats what i've been looking for!!!! think i'll pass parameters in as an arraylist... although not certain yet...

        B 1 Reply Last reply
        0
        • B blakey404

          works perfectly! thanks thats what i've been looking for!!!! think i'll pass parameters in as an arraylist... although not certain yet...

          B Offline
          B Offline
          Broken Bokken
          wrote on last edited by
          #4

          you should look into using the params keyword instead of an arraylist.

          public void MyMethod(params object[] parameters)
          {
          //do stuff
          }

          When you call it you can pass them in without having to create a list. You can add as many parameters as you want and is great when you need to pass a list as a parameter to a method.

          Broken Bokken You can't carry out a ninja-style assasination dressed as an astronaut. It's the luminous fabric; too visible. - Tripod http://www.brokenbokken.com

          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