我正在尝试通过dataetimepicker's
month and year value
与类型的数据库列中存储的日期进行比较来获取 ID Date/Time
,下面是我用来执行此操作的查询,但它在此行显示以下错误while (rs.Read())
错误
No value given for one or more required parameters.
代码
public int GetDrID_MonthWise(string DrName,int month,int year, int refDrID)
{
int data = 0;
try
{
string sql = "Select d.DoctorID From Doctor_Master d,Patient_registration p where d.LastName + ' ' + d.FirstName = '" + DrName + "' AND datepart(mm,p.[RegDate])=@month AND datepart(yyyy,p.[RegDate])=@year AND p.DoctorID=" + refDrID;
cmd = new OleDbCommand(sql, acccon);
cmd.Parameters.AddWithValue("@month", month);
cmd.Parameters.AddWithValue("@year", year);
rs = cmd.ExecuteReader();
while (rs.Read())
{
data = Convert.ToInt32(rs[0]);
}
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString());
}
return data;
}
我正在传递这样的月份和年份值,我在哪里做错了?
int month = dateTimePickerMonth.Value.Month;
int year = dateTimePickerMonth.Value.Year;