Groups | Blog | Home
all groups > dotnet ado.net > may 2007 >

dotnet ado.net : Results to textbox


backwards15 NO[at]SPAM gmail.com
5/27/2007 8:41:17 PM
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
backwards15 NO[at]SPAM gmail.com
5/28/2007 12:37:10 AM
[quoted text, click to view]


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

Regards,

Andy

Scott M.
5/28/2007 1:34:08 AM
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

[quoted text, click to view]

Cor Ligthert [MVP]
5/28/2007 6:45:53 PM
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

<backwards15@gmail.com> schreef in bericht
news:1180337830.191958.67800@i38g2000prf.googlegroups.com...
[quoted text, click to view]

AddThis Social Bookmark Button