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

前端 未结 3 1263
梦毁少年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条回答
  •  迷失自我
    2021-01-22 13:18

    As error message says; OleDbDataReader has no constructor.

    From documentation of OleDbDataReader;

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

    You can use ExecuteReader method that returns OleDbDataReader

    OleDbDataReader dr = cmd.ExecuteReader();
    

    And you need add your parameter values before you call ExecuteReader method.

    Also use using statement to dispose your OleDbConnection, OleDbCommand and OleDbDataReader like;

    using(OleDbConnection myCon = new OleDbConnection(conString))
    using(OleDbCommand cmd = myCon.CreateCommand())
    {
        //Define your sql query and add your parameter values.
    
        using(OleDbDataReader dr = cmd.ExecuteReader())
        {
           //
        }  
    }
    

    And as Steve mentioned, OleDbDataReader.Read method returns boolean value (true of false) and it reads your OleDbDataReader results row by row. You might need to consider to use the result of this method like in a while statement. For example;

    while(reader.Read())
    {
        //Reads your results until the last row..
    }
    

    As a final words, I strongly suspect you store your passwords as plain text. Don't do that! Use SHA-512 hash.

提交回复
热议问题