Guest User

Untitled

a guest
Oct 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. public void Delete() { SqlConnection conSQL = new SqlConnection(mConnectionString); SqlCommand comSQL = new SqlCommand(); comSQL.CommandType = mTypeofDeleteCommand; switch (mTypeofDeleteCommand) { case CommandType.StoredProcedure: comSQL.CommandText = mSPNameforDelete; Type t = mTableObject.GetType(); MemberInfo[] mi = t.GetMembers(); foreach (MemberInfo m in mi) { object[] o = m.GetCustomAttributes(typeof(AttribDataAccess), true); foreach (object ma in o) { AttribDataAccess d = (AttribDataAccess)ma; if (d.IsUsedInDelete) { object returnValue = null; returnValue = t.InvokeMember(m.Name, BindingFlags.GetProperty, null, mTableObject, new object[] { }); SqlParameter arrprmSQL = new SqlParameter("@" + m.Name, d.DatabaseType); arrprmSQL.Direction = d.ParameterDirection; if (d.ParameterSize > 0) arrprmSQL.Size = d.ParameterSize; arrprmSQL.Value = returnValue; comSQL.Parameters.Add(arrprmSQL); } } } break; } try { conSQL.Open(); comSQL.Connection = conSQL; comSQL.ExecuteNonQuery(); } catch (Exception excpSQL) { throw excpSQL; } //Eğer geri dönüş parametresi mevcutsa geri dönüş değeri, //TableObject nesnesinin ilgili üyesine atanıyor. Type tParam = mTableObject.GetType(); MemberInfo[] miParam = tParam.GetMembers(); foreach (MemberInfo m in miParam) { object[] o = m.GetCustomAttributes(typeof(AttribDataAccess), true); foreach (object ma in o) { AttribDataAccess d = (AttribDataAccess)ma; if (d.ParameterDirection!=ParameterDirection.Input) { try { tParam.InvokeMember(m.Name, BindingFlags.SetProperty, null, mTableObject, new object[] {comSQL.Parameters["@" + m.Name].Value}); } catch{} } } } }
Add Comment
Please, Sign In to add comment