一个存储过程,我用程序执行存储过程查询出一个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;
}
附上SQL语句:select '邮编:'+ZipCode as ZipCode,Address,Customer
from dbo.WhiteCardReplacementData
where convert(varchar(10),UpdateDate,120) between @BeginDate and @EndDate
and Customer!=''谢谢啦
{
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;
}
附上SQL语句:select '邮编:'+ZipCode as ZipCode,Address,Customer
from dbo.WhiteCardReplacementData
where convert(varchar(10),UpdateDate,120) between @BeginDate and @EndDate
and Customer!=''谢谢啦
解决方案 »
- C#如何实现鼠标放到PictureBox上就显示信息以及数据定时刷新?
- 十万火急,请大家帮个忙,如何在winform中做一个datagrid与在web上的datagrid针对每行后面有一个编辑和删除的功能呢?
- 请问大家,NHibernate是一项成熟的技术吗?用NHibernate做项目是不是有很大风险?
- C#线程问题,急,切,盼解答,谢谢
- 高分求一个WINFROM窗体之间传递参数的问题
- 简单拿分问题:怎么在web form中点击CheckBox改变选种状态,怎么CheckBox1_CheckedChanged好象没有执行,调试该函数根本没进去
- 请问VS2003的Usercontrol有提供滚动事件吗?如果没有该怎么办?
- 用C#写的程序,要怎么样调用一个可执行文件
- 请教高手和专家:在窗体的 TitleBar 上单击(MouseDown也可),我要在程序中响应这次单击(MouseDown),要怎样做???
- 本人计算机小白,c#问题求教
- xml通过webservice传输的问题
- myxls导出GridView到excel文件时出现的怪问题,xls文件中会包含整个网页的代码!
把你程序里查询亮语句输出,
然后到 sql 里去执行