Example #1
0
        public string Insert(relative obj)
        {
            string        mess = "";
            SqlConnection con  = db.getConnection();

            con.Open();
            SqlCommand cmd = new SqlCommand("addrelative", con);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@name", SqlDbType.VarChar).Value          = obj.name;
            cmd.Parameters.Add("@dateofbirth", SqlDbType.DateTime).Value  = obj.dateofbirth;
            cmd.Parameters.Add("@workplace", SqlDbType.NVarChar).Value    = obj.name;
            cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value      = obj.address;
            cmd.Parameters.Add("@placeofbirth", SqlDbType.NVarChar).Value = obj.placeofbirth;
            cmd.Parameters.Add("@relationship", SqlDbType.NVarChar).Value = obj.relationship;
            cmd.Parameters.Add("@studentcode", SqlDbType.VarChar).Value   = obj.studentcode;
            //cmd.Parameters.Add("@lockdate", SqlDbType.DateTime).Value = obj.LOCKDATE;
            if (cmd.ExecuteNonQuery() == 0)
            {
                mess = "Thêm thất bại";
            }
            else
            {
                mess = "Thêm thành công:" + obj.name;
            }
            con.Close();
            return(mess);
        }
Example #2
0
        public relative GetRelativeByCode(string code)
        {
            SqlConnection con = db.getConnection();

            con.Open();
            //Sử dụng proc addclass đã tạo trong SQL sever
            SqlCommand cmd = new SqlCommand("seachCodeRelative", con);

            cmd.CommandType = CommandType.StoredProcedure; //Xác định khai báo trên là proc nằm trong StoredProcedure trong SQL
            cmd.Parameters.Add(new SqlParameter("@code", code.Trim()));
            DataTable      ds  = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(cmd);

            sda.Fill(ds); //Ds lớp lưu đưới dạng dataTable
            relative tmC = new relative();

            tmC.code         = ds.Rows[0]["code"].ToString();
            tmC.name         = ds.Rows[0]["name"].ToString();
            tmC.dateofbirth  = Convert.ToDateTime(ds.Rows[0]["dateofbirth"]);
            tmC.workplace    = ds.Rows[0]["workplace"].ToString();
            tmC.address      = ds.Rows[0]["address"].ToString();
            tmC.placeofbirth = ds.Rows[0]["placeofbirth"].ToString();
            tmC.relationship = ds.Rows[0]["relationship"].ToString();
            tmC.studentcode  = ds.Rows[0]["studentcode"].ToString();
            //Chuyển dataTable thành dạng List
            con.Close();
            return(tmC);
        }