Ejemplo n.º 1
0
        public DataSet Create(Employee employee)
        {
            DataSet ds      = new DataSet();
            string  message = "";

            if (HttpContext.Current.Request.HttpMethod == "POST")
            {
                SqlConnection conn = EmpWS.GetDBInstance();
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "AddEmployeeReturnID";

                cmd.Parameters.AddWithValue("@title", employee.title.ToString());
                cmd.Parameters.AddWithValue("@first_name", employee.first_name.ToString());
                cmd.Parameters.AddWithValue("@last_name", employee.last_name.ToString());
                cmd.Parameters.AddWithValue("@designation", employee.designation.ToString());
                cmd.Parameters.AddWithValue("@dob", Convert.ToDateTime(employee.dob));
                cmd.Parameters.AddWithValue("@father_name", employee.father_name.ToString());
                cmd.Parameters.AddWithValue("@department", employee.department.ToString());
                cmd.Parameters.AddWithValue("@gender", employee.gender.ToString());
                cmd.Parameters.AddWithValue("@spouse_name", employee.spouse_name.ToString());
                cmd.Parameters.AddWithValue("@permanent_address", employee.permanent_address.ToString());
                cmd.Parameters.AddWithValue("@temporary_address", employee.temporary_address.ToString());
                cmd.Parameters.AddWithValue("@avatar_path", employee.avatar_path);
                cmd.Parameters.AddWithValue("@created_at", DateTime.Now);
                cmd.Connection = conn;

                try {
                    object obj = cmd.ExecuteNonQuery();
                    message = "Record inserted successfully. ID = " + obj.ToString();

                    // Read the employee and return
                    string         query = "SELECT * from employee WHERE id=" + obj.ToString();
                    SqlDataAdapter da    = new SqlDataAdapter(query, conn);
                    da.Fill(ds);
                }
                catch (SqlException err) {
                    message  = "Error inserting record:";
                    message += err.Message;
                    throw new Exception(message);
                } finally {
                    conn.Close();
                }
            }

            return(ds);
        }
Ejemplo n.º 2
0
        public DataSet Get(string column, string value)
        {
            SqlConnection conn = EmpWS.GetDBInstance();
            DataSet       ds   = new DataSet();

            string query = "SELECT * from employee";

            if (column != "" && value != "")
            {
                query += " WHERE " + column + " LIKE '%" + value + "%'";
            }

            try {
                SqlDataAdapter da = new SqlDataAdapter(query, conn);
                da.Fill(ds);
            } finally {
                conn.Close();
            }

            return(ds);
        }