skip to Main Content

I am just a beginner in databasing and after I used this, it only shows msgbox that says unknown command.

Try
    connectionDB.Open()
    cmdDB.CommandText = "SELECT * FROM rescuers WHERE LastName='" & searchres.Text & "';"
    readDB = cmdDB.ExecuteReader()
    With readDB
        .Read()
        rescid.Text = .Item("RescuerID")
        lname.Text = .Item("LastName")
        fname.Text = .Item("FirstName")



        .Close()
    End With

2

Answers


  1. Try setting up the sqlcommand and sqldatareader like so :

        Dim command As New SqlCommand("SELECT * FROM rescuers WHERE LastName='" & searchres.Text & "'", connection)
        Dim reader As SqlDataReader = command.ExecuteReader()
    

    Post your code for setting up the SqlConnection as well.

    Login or Signup to reply.
  2. Try the following, using parameters to avoid SQL injection

    cmdDB = New SqlCommand("SELECT * FROM rescuers WHERE LastName = @LastName", DatabaseConnection)
    
    cmdDB.Parameters.AddWithValue("@LastName", searchres.Text)
    
    readDB = cmdDB.ExecuteReader()
    

    this is assuming that you have already defined your reader like this:

    Dim readDB As SqlDataReader
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search