C#-Function as Part of an SQL-Where-Clause
-
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.
-
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.
Try sqlString = "... Where Status = 'A' And 1=" + ((int)lRes).ToString(); Ravindra Sadaphule MCSD.NET
-
Try sqlString = "... Where Status = 'A' And 1=" + ((int)lRes).ToString(); Ravindra Sadaphule MCSD.NET
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