private void SaveorUpdateLedger(string storedProcName) { DBSQLServer db = new DBSQLServer(AppSetting.ConnectionString()); db.SaveOrUpdateRecord(storedProcName, GetObjectLedger()); } private List<ledgerinsert> GetObjectLedger() { List<ledgerinsert> ledgerList = new List<ledgerinsert>(); foreach (DataRow dr in Datatable.dtLedger.Rows) { LedgerInsert ledger = new LedgerInsert(); ledger.Entry_Date = Convert.ToDateTime(dr["Entry_Date"]); ledger.Entry_Type = Convert.ToInt32(dr["Entry_Type"]); ledger.Party_ID = Convert.ToInt32(dr["Party_ID"]); ledger.Detail = Convert.ToString(dr["Detail"]); ledger.Amount = Convert.ToDecimal(dr["Amount"]); ledger.Account_Type = Convert.ToInt32(dr["Account_Type"]); ledger.User_ID = Convert.ToInt32(dr["User_ID"]); ledger.Sr_No = Convert.ToInt32(dr["Sr_No"]); ledger.PartyID_CR = Convert.ToInt32(dr["PartyID_CR"]); ledger.Region_ID = Convert.ToInt32(dr["Region_ID"]); ledger.Sector_ID = Convert.ToInt32(dr["Sector_ID"]); ledger.Company_ID = Convert.ToInt32(dr["Company_ID"]); ledger.PartyID_DR = Convert.ToInt32(dr["PartyID_DR"]); ledgerList.Add(ledger); } dgvPurchase.DataSource = ledgerList; return ledgerList; }
//SAVE OR UPDATE EXECUTE NON-QUERY public void SaveOrUpdateRecord(string storedProceName, object obj) { using (SqlConnection conn = new SqlConnection(_connstring)) { using (SqlCommand cmd = new SqlCommand(storedProceName, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); //Parameters Type type = obj.GetType(); BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; PropertyInfo[] properties = type.GetProperties(flags); foreach (var property in properties) { cmd.Parameters.AddWithValue("@" + property.Name, property.GetValue(obj, null)); } cmd.ExecuteNonQuery(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)