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?
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?