-1

I'm building a client database system for a travel company.

They want to be able to retrieve all of their customer emails with one click, and have it appear on a textbox on the page, where they can copy it off and paste it into Outlook.

Currently, the textbox is called emailList, and is invisible until the button called emailGet is clicked.

However, I have no idea how to make the text appear into the textbox from an SQL query.

My SQL query is: SELECT CEmail FROM Clients. That's pretty much it.

In pseudocode, what I'm trying to do is:

sqlQuery = "SELECT CEmail FROM Clients"
Execute select query and store results (in a variable? or maybe directly to the textbox?)
emailList.Text = Result of sqlQuery

Thank you! :)

1
  • 2
    you need to use an sql reader for this. Check this out. SO. Next time use search function... Commented Jul 11, 2013 at 21:58

1 Answer 1

1
Private Sub GetEmailAddresses() 
        Dim sText As String = String.Empty
    Dim sConnString As String = String.Empty 'Put your connection string in here

    Using cn As New OleDb.OleDbConnection(sConnString)
        cn.Open()
        Dim cmd As New OleDb.OleDbCommand("SELECT CEmail FROM Clients", cn)
        Dim r As OleDb.OleDbDataReader = cmd.ExecuteReader()

        If Not r.HasRows Then Exit Sub

        Do While r.Read()
            sText = sText & ";" & r.GetString(0)
        Loop

        cn.Close()
    End Using

    txtboxList.Text = sText
End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply! :) My connection string is PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|AlfarisGuestsDB.mdb, and once I made sConnString = what I wrote above, it said that the keyword provider was not recognized :/ I always use that connection string and it works fine.
What I used above was a connection for a SQL database. If you are using an Access database, then you'll want an OLEDB connection. I've modified my answer to reflect that
Ah, that's interesting. Learned something new today. :D Thanks a billion, my friend!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.