Error: The type 'System.Data.OleDb.OleDbDataReader' has no constructors defined

前端 未结 3 1236
梦毁少年i
梦毁少年i 2021-01-22 12:28

I am trying to change password option with ms access database....

please help me folks....

here the code: default.aspx.cs

protected void Button1         


        
3条回答
  •  梦毁少年i
    2021-01-22 13:35

    As MSDN clearly states, To create an OleDbDataReader, you must call the ExecuteReader method of the OleDbCommand object, instead of directly using a constructor.

    You cannot instantiate it using new, which is what you are doing and which is why you get the error. Remove the offending line and change it to this to get rid of the error:

    OleDbDataReader reader = cmd.ExecuteReader();
    

    Also, remember to use using blocks to ensure resources get properly disposed.

    using(OleDbConnection myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["vhgroupconnection"].ConnectionString))
    {
     OleDbCommand cmd = new OleDbCommand(q, myCon);
    
     //Add parameters etc
    
    OleDbDataReader reader = cmd.ExecuteReader();
    
    //Rest of the processing
    }
    

提交回复
热议问题