Results to textbox

B

backwards15

Hi all,

Just having a bit of trouble in returning the results of the SQL
SELECT statement to a textbox

This is only to return one row and i'm not sure how to get it to
display in the text box.

here is my code so far

Private Sub Btn_find_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Btn_find.Click
sql.ConnectionString = ("Data Source=" +
Me.Combo_kiosk.Text.ToString() + ";Application Name = " +
Application.ProductName + ";Initial Catalog=test;Integrated
Security=SSPI")
sql.Open()

cmd.Connection = sql
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT OfferID FROM smspromotionaloffer
WHERE OfferKioskText LIKE '%" + Me.txt_input.Text + "%'"

'cmd.ExecuteReader()

Dim ds As New DataSet()
Dim da As New SqlClient.SqlDataAdapter(cmd)
da.Fill(ds, "Output")
txt_offer.Text = ds.Tables(0).Columns(0).ToString

sql.Close()

End Sub


Atm i get the coloum name show in the textbox. i'm rather new to
programing and i know thats not the right way of doing this.

thanks in adavance

Andy
 
S

Scott M.

Well, your code indicates that you want the name of a column in the textbox.
Is that right, or did you want the value of one of the columns in your
textbox?

Instead of this (to get the the first column's name):
txt_offer.Text = ds.Tables(0).Columns(0).ToString

Use this to get the first column's value:
txt_offer.Text = ds.Tables(0).Rows(0).Item(0).ToString

-Scott
 
B

backwards15

Well, your code indicates that you want the name of a column in the textbox.
Is that right, or did you want the value of one of the columns in your
textbox?

Instead of this (to get the the first column's name):
txt_offer.Text = ds.Tables(0).Columns(0).ToString

Use this to get the first column's value:
txt_offer.Text = ds.Tables(0).Rows(0).Item(0).ToString

-Scott














- Show quoted text -


thanks so much. The second of those two was the one i was after.

Regards,

Andy
 
C

Cor Ligthert [MVP]

Hi Backwards,

Is it possible for you in the Microsoft newsgroups to do the standard
TopPosting, for Netscape and Apple newsgroups you can than use the other
way, just like the etiquette in those newsgroups.

I was looking if Scott his answer was fulfilling your question. A simple
"That helps" in top had been enough. This message of course not alone for
you.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top