开发者

No Value given for one or more requirement parameters

开发者 https://www.devze.com 2023-02-04 02:16 出处:网络
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]) = ?\";

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消