How to write a function which checks for the data value and returns a boolean value

Hi Everyone,

I am trying to write a function in c# and I have a query in it and the function should return true if the data value is not null?

How can I write this function in C#?

Thanks,
D.
developer2012Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
so you have to query a database? please post your code so far.
0
developer2012Author Commented:
Here is my code

  public bool CheckID(string attnum)
        {
            string _depid = null;
            if (!(attnum == null))
            {
                string ConString = "User Id=t;Password=t;Data Source=T";
                using (OracleConnection con = new OracleConnection(ConString))
                {
                    OracleDataAdapter adapter = new OracleDataAdapter();
                    con.Open();
                    OracleCommand command = new OracleCommand("Select ID from Employees Where ID > 0 AND ID Is not NULL AND Attr_Num = '" + attnum + "' ", con);

                    adapter.SelectCommand = command;
                    DataSet dataset = new DataSet("ATTID");
                    adapter.Fill(dataset);
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        _depid = dr["ID"].ToString();
                    }
                    con.Close();
                }
                if(!(_depid == null))
                 return true
            }
           
        }

Open in new window


And the above code throws an error ' The code function path does not return any value'
0
Jaime OlivaresSoftware ArchitectCommented:
You don't need the data adapter, only ExecuteScalar.

        public bool CheckID(string attnum)
        {
            object ret = null;
            if (attnum != null)
            {
                string ConString = "User Id=t;Password=t;Data Source=T";
                using (OracleConnection con = new OracleConnection(ConString))
                {
                    con.Open();
                    OracleCommand command = new OracleCommand("Select ID from Employees Where ID > 0 AND ID Is not NULL AND Attr_Num = '" + attnum + "' ", con);

                    ret = command.ExecuteScalar();
                }
            }
            return ret != null;
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.