[英]Pass DateTimePicker Value to a stored procedure C#
我有DataGridView
和DateTimePicker
,我想基于DateTimePicker
值在DataGridView
显示数据。
这是存储过程:
create proc Get_Employers_All_Day
@Date_Day date
as
SELECT
[Employer_ID] as 'رقم الموظف'
, Employer_Name as 'اسم الموظف'
FROM [dbo].[Come_Out]
inner join Employers
on Employers .Epmloyer_ID = Come_Out .Employer_ID
where
Come_Out .Status = '2'
and Come_Out .Data_Come_Out = @Date_Day
这是C#代码:
public void Get_Employers_All_Day(DateTime Date_Day)
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DAL.Open();
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@Date_Day", SqlDbType.DateTime);
param[0].Value = Date_Day;
DAL.ExecuteCommand("Get_Employers_All_Day", param);
DAL.Close();
}
和事件:
private void Frm_Daily_Come_Out_Load(object sender, EventArgs e)
{
BL.Employers emp = new BL.Employers();
dataGridView1.DataSource = emp.Get_Employers_All_Day(dateTimePicker1 .Value );
}
错误是:
无法将类型“ void”隐式转换为“ object”
您的Get_Employers_All_Day()
方法的返回类型为void
,这意味着它没有返回类型。
对其进行修改以返回所需的数据。 例如,如果您的DAL.ExecuteCommand()
返回一个DataTable
,请对其进行修改以返回它:
public DataTable Get_Employers_All_Day(DateTime Date_Day)
{
...
...
DataTable result;
try
{
result = DAL.ExecuteCommand("Get_Employers_All_Day", param);
}
finally
{
// Even if ExecuteCommand() fails, close any open connections
DAL.Close();
}
return result;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.