public static System.Collections.Generic.IEnumerable<TElement> RunSP<TElement>(this Database self, string spName, params SqlParameter[] paras) { System.Collections.Generic.IEnumerable<TElement> entityList = new System.Collections.Generic.List<TElement>(); DataSet set = self.RunSP(spName, paras); if ((set != null) && (set.Tables.get_Count() >= 1)) { entityList = EntityHelper.GetEntityList<TElement>(set.Tables.get_Item(0)); } return entityList; } public static DataSet RunSP(this Database self, string spName, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command = new SqlCommand(spName, connection)) { adapter.set_SelectCommand(command); command.set_CommandType(CommandType.StoredProcedure); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command.Parameters.Add(parameter2); } } DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } } public static DataSet RunSP(this Database self, string spName, SqlTransaction tran, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command = new SqlCommand(spName, connection)) { if (tran != null) { command.set_Transaction(tran); } adapter.set_SelectCommand(command); command.set_CommandType(CommandType.StoredProcedure); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command.Parameters.Add(parameter2); } } DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } } public static System.Collections.Generic.IEnumerable<TElement> RunSql<TElement>(this Database self, string command, params SqlParameter[] paras) { System.Collections.Generic.IEnumerable<TElement> entityList = new System.Collections.Generic.List<TElement>(); DataSet set = self.RunSql(command, paras); if ((set != null) && (set.Tables.get_Count() >= 1)) { entityList = EntityHelper.GetEntityList<TElement>(set.Tables.get_Item(0)); } return entityList; } public static DataSet RunSql(this Database self, string command, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command2 = new SqlCommand(command, connection)) { command2.set_CommandType(CommandType.Text); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command2.Parameters.Add(parameter2); } } adapter.set_SelectCommand(command2); DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } } public static DataSet RunSql(this Database self, string command, SqlTransaction tran, params SqlParameter[] paras) { if (paras != null) { SqlParameter[] parameterArray = paras; for (int i = 0; i < parameterArray.Length; i = (int) (i + 1)) { SqlParameter parameter = parameterArray[i]; if (parameter.get_Value() == null) { parameter.set_Value(System.DBNull.Value); } } } SqlDataAdapter adapter = new SqlDataAdapter(); SqlConnection connection = self.Connection as SqlConnection; using (SqlCommand command2 = new SqlCommand(command, connection)) { if (tran != null) { command2.set_Transaction(tran); } command2.set_CommandType(CommandType.Text); if (paras != null) { SqlParameter[] parameterArray2 = paras; for (int j = 0; j < parameterArray2.Length; j = (int) (j + 1)) { SqlParameter parameter2 = parameterArray2[j]; command2.Parameters.Add(parameter2); } } adapter.set_SelectCommand(command2); DataSet set = new DataSet(); adapter.Fill(set); adapter.SelectCommand.Parameters.Clear(); return set; } }
时间: 2024-10-11 17:24:32