user3415629
user3415629

Reputation: 47

Text Box to retrieve information from database

I'm trying to display information on a piece of equipment the idea is that the user will type in an ID in the textbox and it will display the information on a grid view:

 Dim ID As String = TxtSearch.Text
        Dim cmd As SqlCommand

        Dim ds As String = "Select * from Medical_Equipment where AssetID='" & ID & "''"
        Dim strConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim con As New SqlConnection(strConnString)
        cmd = New SqlCommand(ds, con)


        Try
            con.Open()
            GridView1.EmptyDataText = "No equipment with that Asset ID"
            GridView1.DataSource = cmd.ExecuteReader()
            GridView1.DataBind()
        Catch ex As Exception
            Throw ex
        Finally
            con.Close()
            con.Dispose()
        End Try

    End Sub

But it is not displaying the information Unclosed quotation mark after the character string '1001''.Incorrect syntax near '1001''

Upvotes: 0

Views: 63

Answers (2)

jomsk1e
jomsk1e

Reputation: 3625

I think you have a typo here:

Try this:

"Select * from Medical_Equipment where AssetID='" & ID & "'" 

Upvotes: 0

ɐsɹǝʌ ǝɔıʌ
ɐsɹǝʌ ǝɔıʌ

Reputation: 4512

If AssetID is defined as numeric at database level the SQL statement should be:

"SELECT * FROM Medical_Equipment WHERE AssetID=" & ID 

If it is defined as text then should be:

"SELECT * FROM Medical_Equipment WHERE AssetID='" & ID & "'" 

Upvotes: 1

Related Questions