Exemplo n.º 1
0
        public bool them(NV_DM_LinhVucKinhDoanh_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_LinhVucKinhDoanh_add", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;


                    SqlParameter pTenLinhVuc = new SqlParameter("@TenLinhVuc", SqlDbType.NVarChar, 250);
                    pTenLinhVuc.Value = model.TenLinhVuc;
                    myCommand.Parameters.Add(pTenLinhVuc);


                    SqlParameter pStt = new SqlParameter("@Stt", SqlDbType.Int);
                    pStt.Value = model.Stt;
                    myCommand.Parameters.Add(pStt);

                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public NV_DM_LinhVucKinhDoanh_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_LinhVucKinhDoanh_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    SqlParameter pID = new SqlParameter("@ID", SqlDbType.Int);
                    pID.Value = id;
                    myCommand.Parameters.Add(pID);

                    DataTable dt;
                    NV_DM_LinhVucKinhDoanh_ChiTiet model = new NV_DM_LinhVucKinhDoanh_ChiTiet();

                    myConnection.Open();
                    using (SqlDataAdapter mData = new SqlDataAdapter(myCommand))
                    {
                        dt = new DataTable();
                        mData.Fill(dt);
                    }
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        model.ID         = id;
                        model.TenLinhVuc = dt.Rows[0]["TenLinhVuc"].ToString();
                        model.Stt        = int.Parse(dt.Rows[0]["Stt"].ToString());
                    }
                    return(model);
                }
            }
        }