I m 存在按日田搜索数据的问题。
我有一个储存的搜寻程序:
ALTER PROCEDURE [dbo].[spSearchTraining]
(
@CourseName VARCHAR(50)= null,
@TrainingProvider VARCHAR(50)= null,
@TrainingCost VARCHAR(50) = null,
@StartDate Varchar(50) = null,
@EndDate Varchar(50)= null,
@RowCount int output
)
AS
BEGIN
SELECT * FROM vwTrainingDetails
WHERE ( CourseName Like % + @CourseName + % or @CourseName is null)
AND ( TrainingProvider Like % + @TrainingProvider + % or @TrainingProvider is null)
AND ( Cost Like % + @TrainingCost + % or @TrainingCost is null)
AND ([Start Date] >= @StartDate or @StartDate is null)
AND ([Start Date] <= @EndDate or @EndDate is null)
select @RowCount=@@ROWCOUNT
END
我的参数如下:
//Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@CourseName", SqlDbType.VarChar, 40));
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@TrainingProvider", SqlDbType.VarChar, 40));
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@TrainingCost", SqlDbType.VarChar, 40));
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.VarChar, 40));
MyDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@EndDate", SqlDbType.VarChar, 40));
//string mysdate = (StartTextBox.Text).ToString;
//Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters["@CourseName"].Value = (CourseTextBox.Text).Trim();
MyDataAdapter.SelectCommand.Parameters["@TrainingProvider"].Value = (ProviderTextBox.Text).Trim();
MyDataAdapter.SelectCommand.Parameters["@TrainingCost"].Value = (CostTextBox.Text).Trim();
MyDataAdapter.SelectCommand.Parameters["@StartDate"].Value = (StartTextBox.Text);
MyDataAdapter.SelectCommand.Parameters["@EndDate"].Value =(EndTextBox.Text);
Problem I m having is that when I run as is the stored procedure does not return anything. If I comment out :
MyDataAdapter.SelectCommand.Parameters["@StartDate"].Value = (StartTextBox.Text);
MyDataAdapter.SelectCommand.Parameters["@EndDate"].Value =(EndTextBox.Text);
然后它运作,但无法使用日期进行搜索。
当我从服务器上执行所储存的程序并在包括日期在内的参数上通过时,它会进行罚款。
谁能帮助我,看一看我做的错!
成就