一个很奇怪的问题,大家来帮帮忙。。。
一个存储过程,我用程序执行存储过程查询出一个dataTable里面是71条数据,但是我直接在数据库中执行的话,返回的数据条数是79条,这个问题好奇怪啊。。。上代码:
public static DataTable WhiteCardReplacementData(string beginDate, string enddate,string dateType) { DataTable dt = new DataTable(); SqlParameter[] para = new SqlParameter[] { new SqlParameter("@BeginDate",beginDate), new SqlParameter("@EndDate",enddate), new SqlParameter("@DateType",dateType) }; try { dt = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionString, CommandType.StoredProcedure, "usp_Report_WhiteCardData", para); return dt; } catch (Exception e) { throw; } }//Sqlhelper中的代码: public static DataTable ExecuteDataTable(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters) { if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString"); // Create & open a SqlConnection, and dispose of it after we are done using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); // Call the overload that takes a connection in place of the connection string return ExecuteDataTable(connection, commandType, commandText, commandParameters); } }public static DataTable ExecuteDataTable(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters) { if (connection == null) throw new ArgumentNullException("connection"); // Create a command and prepare it for execution SqlCommand cmd = new SqlCommand(); bool mustCloseConnection = false; PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection); // Create the DataAdapter & DataSet using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); // Fill the DataSet using default values for DataTable names, etc da.Fill(dt); // Detach the SqlParameters from the command object, so they can be used again cmd.Parameters.Clear(); if (mustCloseConnection) connection.Close(); // Return the datatable return dt; } }private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection) { if (command == null) throw new ArgumentNullException("command"); if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText"); // If the provided connection is not open, we will open it if (connection.State != ConnectionState.Open) { mustCloseConnection = true; connection.Open(); } else { mustCloseConnection = false; } // Associate the connection with the command command.Connection = connection; // Set the command text (stored procedure name or SQL statement) command.CommandText = commandText; // If we were provided a transaction, assign it if (transaction != null) { if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction"); command.Transaction = transaction; } // Set the command type command.CommandType = commandType; // Attach the command parameters if they are provided if (commandParameters != null) { AttachParameters(command, commandParameters); } return; }
select '邮编:'+ZipCode as ZipCode,Address,Customer from dbo.WhiteCardReplacementData where convert(varchar(10),UpdateDate,120) between @BeginDate and @EndDate and Customer!=''