Solved

How do i find out if a value exists in a table in sql compact edition

Posted on 2009-07-05
4
176 Views
Last Modified: 2013-12-07
In C# i want to know if a value exists in a column within a table.  I can't find or figure out the syntax.  I think i am looking for a function that returns the number of rows if found, but i cant find that function for sql compact edition in the class SqlCeCommand.
Thanks,
32Handicap
0
Comment
Question by:32handicap
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 500 total points
ID: 24782925
See, you need to check for the DataReader.HasRows property.
Aftere execulting the SQLCommand you will be retrieving resultset. get the DataReader and check with the property mentioned
0
 
LVL 14

Expert Comment

by:shru_0409
ID: 24784109

may be this query help u

CREATE OR REPLACE FUNCTION F_exist
RETURN boolean IS

BEGIN
 SELECT dept_no, dept_name
   FROM   dept D
   WHERE  EXISTS ( SELECT 'X'
                   FROM   emp E
                   WHERE  E.dept_no = D.dept_no );
  EXCEPTION
  WHEN NO_DATA_FOUND THEN
    RETURN FALSE ;

RETURN TRUE;
END;
/
0
 

Author Comment

by:32handicap
ID: 24791177
I tried DataReader.HasRows property and this doesn't work in sql compact edition, "unless you have active cursor", or something like that, (which i do not).  But following along those lines i found I just need to return   reader.Read().  If there is anything to read it will be true, else false.  So i think that will do it unless anybody else has a better way.

 On the other solution, i did not want to do anything that would cause an exception as part of my "normal" code.  

Thanks both for the help

0
 

Author Closing Comment

by:32handicap
ID: 31600030
thanks,
32handicap
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pivot rows to columns 1 35
average of calculation (TSQL) 4 26
Comparison query - 4 columns 9 25
Setting variables in a stored procedure 4 15
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question