No Value given for one or more requirement parameters
Plz tell me where I am doing wrong, I am copying the part of code having trouble
query = "SELECT * FROM ACCOUNT_KEEPER WHERE DATEPART(MONTH,[DATE]) = ?";
开发者_JS百科DataSet dataSet=new DataSet();
OleDbDataAdapter dataAdapter=new OleDbDataAdapter();
try
{
if(OpenOledbConnection())
{
dataAdapter.SelectCommand=new OleDbCommand(query,connection);
dataAdapter.SelectCommand.Parameters.AddWithValue("@DATEPART(MONTH,[DATE]", date.Month);
dataAdapter.Fill(dataSet);
// checking if dataset is updated or not
int temp = dataSet.Tables[0].Rows.Count;
return dataSet;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error While Retrieving data by Month");
}
finally
{
CloseOledbConnection();
}
return null;
Thanks in Advance
MGD
Instead of
query = "SELECT * FROM ACCOUNT_KEEPER WHERE DATEPART(MONTH,[DATE]) = ?";
write
query = "SELECT * FROM ACCOUNT_KEEPER WHERE DATEPART(MONTH,[DATE]) = @x";
and instead of
dataAdapter.SelectCommand.Parameters.AddWithValue("@DATEPART(MONTH,[DATE]", date.Month);
write
dataAdapter.SelectCommand.Parameters.AddWithValue("@x", date.Month);
精彩评论