Plz告诉我我做错了什么,我正在复制有问题的部分代码
query = "SELECT * FROM ACCOUNT_KEEPER WHERE DATEPART(MONTH,[DATE]) = ?";
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;
先谢谢
MGD
答案 0 :(得分:1)
而不是
query = "SELECT * FROM ACCOUNT_KEEPER WHERE DATEPART(MONTH,[DATE]) = ?";
写
query = "SELECT * FROM ACCOUNT_KEEPER WHERE DATEPART(MONTH,[DATE]) = @x";
而不是
dataAdapter.SelectCommand.Parameters.AddWithValue("@DATEPART(MONTH,[DATE]", date.Month);
写
dataAdapter.SelectCommand.Parameters.AddWithValue("@x", date.Month);