Class >

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorandoran
    New Member
    • Feb 2007
    • 145

    Class >

    I created a class and it's working but want to add addition methods. I am adding following method so I can populate a listbox on page load. I may need onload snippet. Also, is the following looks okay cause I am getting this error.
    Assign_Dept.Bin dData(int)': not all code paths return a value

    Code:
        public SqlDataReader BindData(int emp_id)
        {
            string strSQL = @"select d.department_name from departments d
                            where not exists 
                            (select dm.department_name, dm.emp_id from department_membership dm
                            where (d.department_name=dm.department_name) and 
                            (dm.emp_id=@emp_id))";
            SqlConnection conn = new SqlConnection(connStr);
            try
            {
            conn.Open();
                SqlCommand cmd = new SqlCommand(strSQL,conn);
                cmd.Parameters.Add("@emp_id",SqlDbType.Int).Value=emp_id;
                
                SqlDataReader objDR;
                objDR=cmd.ExecuteReader(CommandBehavior.CloseConnection);
                return objDR;
            }
            catch (Exception Ex)
            {
                 Ex.Message.ToString();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                conn.Close();
                }
            }
    
        }
    }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Code:
    public [I]SqlDataReader [/I][B]BindData[/B](int emp_id)
    Means this method named "BindData" is going to return an object of type SqlDataReader

    You're not returning anything.

    Comment

    Working...