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. C#-Function as Part of an SQL-Where-Clause

C#-Function as Part of an SQL-Where-Clause

Scheduled Pinned Locked Moved C#
csharpdatabasesysadminquestion
3 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.
  • R Offline
    R Offline
    Rainer Ziebarth
    wrote on last edited by
    #1

    I'd like to add an UserAccess-Function to a SQL-Select-Statement. It's a normal Statement like "Select * from Table Where Status = 'A'". I'm loooking for a way like "... Where Status = 'A' And AccessFunction()" or bool lRes = AccessFunction(); sqlString = "... Where Status = 'A' And " + lRes.ToString(); I don't like to use UDF's, because the Application should work with several Databases like SQL-Server, Access, Foxpro, ... and I don't like same doing code at several places. Has anyone a helpfull answer ? Best thanks to you.

    R 1 Reply Last reply
    0
    • R Rainer Ziebarth

      I'd like to add an UserAccess-Function to a SQL-Select-Statement. It's a normal Statement like "Select * from Table Where Status = 'A'". I'm loooking for a way like "... Where Status = 'A' And AccessFunction()" or bool lRes = AccessFunction(); sqlString = "... Where Status = 'A' And " + lRes.ToString(); I don't like to use UDF's, because the Application should work with several Databases like SQL-Server, Access, Foxpro, ... and I don't like same doing code at several places. Has anyone a helpfull answer ? Best thanks to you.

      R Offline
      R Offline
      Ravindra Sadaphule
      wrote on last edited by
      #2

      Try sqlString = "... Where Status = 'A' And 1=" + ((int)lRes).ToString(); Ravindra Sadaphule MCSD.NET

      R 1 Reply Last reply
      0
      • R Ravindra Sadaphule

        Try sqlString = "... Where Status = 'A' And 1=" + ((int)lRes).ToString(); Ravindra Sadaphule MCSD.NET

        R Offline
        R Offline
        Rainer Ziebarth
        wrote on last edited by
        #3

        thanks & sorry, seeing your answer I realized, that the second codesnippet in my question dosn't describe my real problem - my mistake. I need a dynamic function call in my SQL-statement such like how in the first codesnippet described ("... Where Status = 'A' And AccessFunction()"). The real problem is, that the functions result depends in normal case on the fieldvalues of the selected records (but I don't like to use UDF's). For instance, there are some access rules for various usergroups (usergroup "xy" may only see the customergroup "ABC", usergroup "yz" but the customergroup "CDE"). My solution now is to add an boolean field to the datasets table after the fill-command, calculate that for every selected record with my accessfunction and use it in my datagrids binded dataview as a rowfilter. Do you know a better direct way for these problem ? thanks for your help, Rainer Ziebarth

        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