コード例 #1
0
ファイル: DanhNhan.cs プロジェクト: BuiDucDinh/QuanLyHoSo
        public NV_DanhNhan_ChiTiet GetByUrl(string url)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_DanhNhan_getByUrl", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pUrl = new SqlParameter("@Url", SqlDbType.NVarChar, 100);
                    pUrl.Value = url;
                    myCommand.Parameters.Add(pUrl);

                    DataTable           dt;
                    NV_DanhNhan_ChiTiet model = new NV_DanhNhan_ChiTiet();

                    myConnection.Open();
                    using (SqlDataAdapter mData = new SqlDataAdapter(myCommand))
                    {
                        dt = new DataTable();
                        mData.Fill(dt);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            model = new NV_DanhNhan_ChiTiet(dt.Rows[0]);
                        }
                        return(model);
                    }
                }
            }
        }
コード例 #2
0
ファイル: DanhNhan.cs プロジェクト: BuiDucDinh/QuanLyHoSo
        public bool them(NV_DanhNhan_ChiTiet model, out int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_DanhNhan_add", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@DanhNhanID", SqlDbType.Int);
                    pID.Direction = ParameterDirection.Output;
                    myCommand.Parameters.Add(pID);

                    SqlParameter pTenDanhNhan = new SqlParameter("@TenDanhNhan", SqlDbType.NVarChar, 100);
                    pTenDanhNhan.Value = model.TenDanhNhan;
                    myCommand.Parameters.Add(pTenDanhNhan);

                    SqlParameter pThoidai = new SqlParameter("@Thoidai", SqlDbType.NVarChar, 100);
                    pThoidai.Value = model.Thoidai;
                    myCommand.Parameters.Add(pThoidai);

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

                    SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NText);
                    pMoTa.Value = model.MoTa;
                    myCommand.Parameters.Add(pMoTa);

                    SqlParameter pUrl = new SqlParameter("@Url", SqlDbType.NVarChar, 100);
                    pUrl.Value = model.Url;
                    myCommand.Parameters.Add(pUrl);
                    id = 0;
                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        id = (int)pID.Value;
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }