Link to home
Start Free TrialLog in
Avatar of developer2012
developer2012

asked on

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.
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

so you have to query a database? please post your code so far.
Avatar of developer2012
developer2012

ASKER

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'
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial