Show Result in textbox

Joined
Jun 16, 2008
Messages
1
Reaction score
0
Hi,

I'm maybe a bit newbie to ASP.NET 2.0 but trying to learn.
I have difficult to show result of a query in textbox, but it works fine in a GridView.


For example, I have this code:




Protected Sub B_Search_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles B_Search.Click
Dim test

test = txtsearch.Text

Dim cs As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\customer.mdf;Integrated Security=True;User Instance=True"
Using con As New System.Data.SqlClient.SqlConnection(cs)
con.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.Connection = con
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = "SELECT companyName FROM T_Customer WHERE companyID like '" + test + "'"
Using reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader


'This only returns System.Data.SqlClient.SqlDataReader in txtResult.Text :

txtResult.Text = reader.ToString
txtResult.DataBind()

'But this is working:

GridView1.DataSource = reader
GridView1.DataBind()



End Using

End Using

End Sub



Any suggestion how to to get the result in txtResult.Text?
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top