hi.. i need help in displaying the search result onto the textboxes when i search for eg.a Disc. like when i type the description to search for a disc, the details of the discs which match the description will appear.
how do i go about doing that?
:?:

Dani AI

Generated

This is why you see "System.Data.OleDb.OleDbCommand": the command object is not the query result. already hinted at that — calling ToString() on an OleDbCommand just returns the object's type. To get values you must execute the command (ExecuteReader / ExecuteScalar / DataAdapter.Fill) and then read fields and assign those strings to your textboxes.

A simple, safe pattern in VB.NET: open an OleDbConnection, use a parameterized LIKE query with wildcards, execute a reader, then copy column values into your TextBox controls. Use Using blocks so connections and readers are always closed, and handle DBNull before calling ToString().

Using conn As New System.Data.OleDb.OleDbConnection(connString)
    conn.Open()
    Using cmd As New System.Data.OleDb.OleDbCommand("SELECT TOP 1 * FROM Books WHERE Title LIKE ?", conn)
        cmd.Parameters.AddWithValue("?", "%" & searchBookTextBox.Text & "%")
        Using rdr As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader()
            If rdr.Read() Then
                titleTextBox.Text = If(IsDBNull(rdr("Title")), "", rdr("Title").ToString())
                authorTextBox.Text = If(IsDBNull(rdr("Author")), "", rdr("Author").ToString())
            Else
                titleTextBox.Text = "No match"
            End If
        End Using
    End Using
End Using

Troubleshooting and tips:

  • If you use an Access (Jet/ACE) DB, wildcard char depends on ANSI mode: older ANSI-89 uses * / ?, ANSI-92 uses % / _. Test which one your DB expects.
  • For multiple matches show a list (GridView/ListBox) and let the user pick which row fills the textboxes.
  • Always use parameters to avoid SQL injection; be careful with AddWithValue (it can infer wrong types) — specify types if you see odd behavior.
  • For ASP.NET, ensure textboxes are server controls (runat="server") and that you populate them on postback handling (not overwriting on Page_Load without IsPostBack).

For API details see the Microsoft docs for OleDbDataReader and OleDbCommand.

Recommended Answers

All 3 Replies

Member Avatar for Member #46692

just do textBox1.text = String whatever

Thanks for your reply.. =)
hmm but what codes should i type after the String?

i did the codings below to test and see if the search is able to work but the search result won't display on the textbox. it displays "System.Data.OleDb.OleDbCommand" instead.
can somebody please help me? :icon_sad:

searchStr = New OleDbCommand("select * from Books where Title LIKE searchBookTextBox.Text%")
                TextBox1.Text = searchStr.ToString()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.