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. Linq

Linq

Scheduled Pinned Locked Moved C#
databasecsharpcsslinq
5 Posts 4 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
    Sayed Sajid
    wrote on last edited by
    #1

    Hi, Am writing a function which should return a dataset to bind to a grid control. It is a linq query, Can I type cast var type variable to DataSet and return it. Here is my funtion below. public DataSet GetSites() { SiteTerDBDataContext ctx = new SiteTerDBDataContext(); ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString; var res = from sites in ctx.tblSites select sites; return (DataSet)res; } Any early replies will be appreciated. regards Sajid

    C N 2 Replies Last reply
    0
    • S Sayed Sajid

      Hi, Am writing a function which should return a dataset to bind to a grid control. It is a linq query, Can I type cast var type variable to DataSet and return it. Here is my funtion below. public DataSet GetSites() { SiteTerDBDataContext ctx = new SiteTerDBDataContext(); ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString; var res = from sites in ctx.tblSites select sites; return (DataSet)res; } Any early replies will be appreciated. regards Sajid

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Sayed Sajid wrote:

      Any early replies will be appreciated.

      You're in a hurry, but you didn't think to try this and see what happened, or check res in the debugger to see what type it is ? I would be stunned if it came back as a dataset. I expect it would be a collection.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      S 1 Reply Last reply
      0
      • S Sayed Sajid

        Hi, Am writing a function which should return a dataset to bind to a grid control. It is a linq query, Can I type cast var type variable to DataSet and return it. Here is my funtion below. public DataSet GetSites() { SiteTerDBDataContext ctx = new SiteTerDBDataContext(); ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString; var res = from sites in ctx.tblSites select sites; return (DataSet)res; } Any early replies will be appreciated. regards Sajid

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Sayed Sajid wrote:

        Can I type cast var type variable to DataSet and return it.

        No. var is just a syntactic sugar. In your case, res will be enumerable of ctx.tblSites's type. You can't cast it directly to a DataSet. Create a DatTable, Iterate the contents of res in a loop and fill data into DataTable. Once data table is ready, add it to a DataSet and return. :)

        Navaneeth How to use google | Ask smart questions

        1 Reply Last reply
        0
        • C Christian Graus

          Sayed Sajid wrote:

          Any early replies will be appreciated.

          You're in a hurry, but you didn't think to try this and see what happened, or check res in the debugger to see what type it is ? I would be stunned if it came back as a dataset. I expect it would be a collection.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          S Offline
          S Offline
          Sayed Sajid
          wrote on last edited by
          #4

          Mr Chris, Thanks for your answer. What would be the appropiate way of returning var type? This is my intension to do actually. public var GetSites() { SiteTerDBDataContext ctx = new SiteTerDBDataContext(); ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString; var res = from sites in ctx.tblSites select sites; return res; } Many thanks. Sajid

          R 1 Reply Last reply
          0
          • S Sayed Sajid

            Mr Chris, Thanks for your answer. What would be the appropiate way of returning var type? This is my intension to do actually. public var GetSites() { SiteTerDBDataContext ctx = new SiteTerDBDataContext(); ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString; var res = from sites in ctx.tblSites select sites; return res; } Many thanks. Sajid

            R Offline
            R Offline
            riced
            wrote on last edited by
            #5

            You cannot return var type since it's not a type like int or string. It simply allows the compiler to infer the real type.

            Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

            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