How to edit using data reader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sacha4
    New Member
    • Sep 2007
    • 11

    How to edit using data reader

    I need to make an edit page using data reader.
    this is my code..
    [code=vbnet]
    Sub Page_Load()
    If Not IsPostBack Then
    Dim conn As SqlConnection
    Dim cmdSQL As SqlCommand
    Dim dataReader As SqlDataReader
    Dim SQL As String

    Dim libBookID As Integer = Request.QuerySt ring("lid")
    conn = New SqlConnection(" Server=xxx.xxx. xxx.xxx;Databas e=projectsurvey s;Uid=surveygro up;Pwd=XXXXXXXX XX")
    cmdSQL = New SqlCommand("get LibraryBook", conn)
    cmdSQL.CommandT ype = CommandType.Sto redProcedure
    cmdSQL.Paramete rs.AddWithValue ("@LibID", libBookID)
    conn.Open()
    dataReader = cmdSQL.ExecuteR eader()
    While dataReader.Read ()
    txtTitle.Text = dataReader("Tit le")
    Select Case (dataReader("Ca tegory").ToStri ng())
    Case "Early Childhood"
    lstMediaType.Se lectedIndex = 0
    Case "School-Aged"
    lstMediaType.Se lectedIndex = 1
    Case "Adult"
    lstMediaType.Se lectedIndex = 2
    End Select
    txtAuthors.Text = dataReader("Aut hor")
    txtPublisher.Te xt = dataReader("Pub lisher")
    txtCity.Text = dataReader("Cit y")
    txtYear.Text = dataReader("Yea r")
    txtISBN.Text = dataReader("ISB N")
    Select Case (dataReader("Me diaType").ToStr ing())
    Case "Audio"
    lstMediaType.Se lectedIndex = 0
    Case "Book"
    lstMediaType.Se lectedIndex = 1
    Case "Manual"
    lstMediaType.Se lectedIndex = 2
    Case "Other"
    lstMediaType.Se lectedIndex = 3
    Case "Periodical "
    lstMediaType.Se lectedIndex = 4
    Case "Seminar/Conference"
    lstMediaType.Se lectedIndex = 5
    End Select
    txtKeywords.Tex t = dataReader("Key words")
    txtComments.Tex t = dataReader("Com ments")
    Select Case (dataReader("Ch eckedOut"))
    Case "Available"
    Status.Selected Index = 0
    Case "Checked Out"
    Status.Selected Index = 1
    End Select

    End While
    dataReader.Clos e()
    conn.Close()
    End If
    End Sub
    [/code]
    I am getting an error saying "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) "

    Please help me!!!
    Last edited by Frinavale; Oct 16 '07, 06:17 PM. Reason: Added [code] tags to make more legible (removed IP to Database)
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Originally posted by sacha4
    I am getting an error saying "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) "
    Well have you taken care of the settings like it says? To allow remote connections, named pipes, and anything else?

    And are you using the write connection string for your database type?

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Hi Sacha4,

      If you have control of your database server, make sure that it allows your code to access it. Since you're not using Windows Integrated Security to connect to it, please ensure that your database's security is set up to authenticate using SQL authentication as well.


      ---------------------------------------------------------------------------------------------------------------

      In the future, please use place any code you post within [code] tags.
      For example, to post a snippet of VB.NET code:
      [code=vb net]
      'My Vb.NET code
      [/code]

      Also, it is not advisable to post your IP and password to your database.
      In the future please take measures to protect this very private information. This is for the safety of your computer.

      Thanks!
      -Moderator/Frinny

      Comment

      Working...