locked
SqlDataReader RRS feed

  • Question

  • User390533404 posted

    Error 1 'System.Data.SqlClient.SqlDataReader.Friend Sub New(command As System.Data.SqlClient.SqlCommand, behavior As System.Data.CommandBehavior)' is not accessible in this context because it is 'Friend'. C:\Users\ozdel\Documents\bitirme_odevi\anons.aspx.vb 64 13 C:\...\bitirme_odevi\

    How Can I fix it this error?

    Friday, April 15, 2016 12:21 PM

Answers

  • User-821857111 posted

    You haven't shown the offending code, but most likely you are declaring and trying to "new up" a SqlDataReader e.g.:

    Dim reader As New SqlDataReader()

    Change that to remove the New:

    Dim reader As SqlDataReader()



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 15, 2016 3:32 PM
  • User753101303 posted

    Hi,

    To second Mikesdotnetting advice the point is that you never need to create the reader yourself using "new" (which is why the constructor is not publicly available). Instead you call a method such as SqlCommand.ExecuteReader that internally creates the reader and return this newly created reader to your code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 15, 2016 3:41 PM

All replies

  • User-821857111 posted

    You haven't shown the offending code, but most likely you are declaring and trying to "new up" a SqlDataReader e.g.:

    Dim reader As New SqlDataReader()

    Change that to remove the New:

    Dim reader As SqlDataReader()



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 15, 2016 3:32 PM
  • User753101303 posted

    Hi,

    To second Mikesdotnetting advice the point is that you never need to create the reader yourself using "new" (which is why the constructor is not publicly available). Instead you call a method such as SqlCommand.ExecuteReader that internally creates the reader and return this newly created reader to your code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 15, 2016 3:41 PM