/// <summary> /// Insert ALL /// </summary> /// <returns></returns> public int Insert() { DatabaseHelper help = new DatabaseHelper(); help.ConnectDatabase(); // insert try { using (var dbcxtransaction = help.ent.Database.BeginTransaction()) { var t = new DM_Vat_Tu //Make sure you have a table called test in DB { Ma_vat_tu = this.Ma_vat_tu, Ten_vat_tu = this.Ten_vat_tu, // ID = Guid.NewGuid(), ID_Don_vi_tinh = this.ID_Don_vi_tinh, Mo_ta = this.Mo_ta, }; help.ent.DM_Vat_Tu.Add(t); help.ent.SaveChanges(); dbcxtransaction.Commit(); return 1; } } catch (Exception ex) { return 0; } ////command.Parameters.Add(new SqlParameter("@Ten_kho", Ten_kho)); ////Mở //m_dbConnection.Open(); ////Chuẩn bị //string sql = ""; //sql += "INSERT INTO DM_Vat_Tu (Ma_vat_tu, Ten_vat_tu, ID_Don_vi_tinh, Mo_ta) "; //sql += "VALUES(@Ma_vat_tu, @Ten_vat_tu, @ID_Don_vi_tinh, @Mo_ta)"; //SqlCommand command = new SqlCommand(sql, m_dbConnection); //command.Parameters.Add("@Ma_vat_tu", SqlDbType.VarChar, 50).Value = Ma_vat_tu; //command.Parameters.Add("@Ten_vat_tu", SqlDbType.NVarChar, 50).Value = Ten_vat_tu; //command.Parameters.Add("@ID_Don_vi_tinh", SqlDbType.Int).Value = ID_Don_vi_tinh; //command.Parameters.Add("@Mo_ta", SqlDbType.NVarChar, 50).Value = Mo_ta; //command.CommandType = CommandType.Text; ////Run //int result = command.ExecuteNonQuery(); ////Đóng //m_dbConnection.Close(); //return result; }
// End Checkduplicaterows /// <summary> /// hàm insert sử dụng transaction /// </summary> /// <returns></returns> public int Insert(DatabaseHelper help) { try { var t = new DM_Vat_Tu //Make sure you have a table called test in DB { Ma_vat_tu = this.Ma_vat_tu, Ten_vat_tu = this.Ten_vat_tu, // ID = Guid.NewGuid(), ID_Don_vi_tinh = this.ID_Don_vi_tinh, Mo_ta = this.Mo_ta??"", Da_xuat =this.Da_xuat, Don_gia =0, Trang_thai =true, Ten_khong_dau = this.Ten_khong_dau??"", }; help.ent.DM_Vat_Tu.Add(t); help.ent.SaveChanges(); return 1; } catch (Exception ex) { return 0; } }