Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi all,

 

I'm having trouble retrieving a record from the DB and displaying the field in a textbox. I want to type a customers phone number in textbox1 and then search the DB for a matching record and display the information in tebox2 For some reason it won't display anything in the textbox2 when I click the button. Here's my code:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= pos.mdb")
       MyConnection.Open()

       Dim MyCommand As New OleDbCommand("SELECT * FROM Customers WHERE Phone LIKE'" & TextBox1.Text & "'", MyConnection)

       Dim MyReader As OleDbDataReader = MyCommand.ExecuteReader()

       While MyReader.Read
           TextBox2.Text = MyReader("Name")


       End While
   End Sub

 

 

Thanks in advance,

 

Chris

Edited by Robby
if(computer.speed == "slow")
    {  
       hamster.feed();  
    }
if(computer.speed == "really slow")
    {  
        hamster.kill();
        BuyNewHamster();
    }

  • 2 weeks later...
Posted

dude, why are you using LIKE if you want an exact match ?

 

SELECT * FROM Customers WHERE Phone = '" & TextBox1.Text & "'"

 

will produce an exact match. Don't forget to test for no match or your code may crash.

  • Administrators
Posted

If you step through the code does the DataReader contain any valid results?

 

Also you may want to trim any whitespace from the textbox before passing it into the select statement.

 

Dim MyCommand As New OleDbCommand("SELECT * FROM Customers WHERE Phone='" & TextBox1.Text.Trim() & "'", MyConnection)

 

Just another thought - not used access in ages (no intention of using it either) but does access use a single quote ' or a double quote to delimit strings?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Shirtster I don't want an exact match....if the user doesn't include (say) the area code, or doesn't include the -'s I want it to be able to pick the record....I'll try the suggestions and see what happens....thanks to the both of you
if(computer.speed == "slow")
    {  
       hamster.feed();  
    }
if(computer.speed == "really slow")
    {  
        hamster.kill();
        BuyNewHamster();
    }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...