Hi,
As I realized you want to show the result in a TextBox instead of a GridView or other controls. Well, you can use SqlDataReader along with SqlCommand to fetch the data and then put it in the TextBox. Here is a sample code:
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;
try
{
string ConnectionString = "server=xeon;uid=sa;"+
"pwd=manager; database=northwind";
con = new SqlConnection(ConnectionString);
con.Open();
string CommandText = "SELECT FirstName, LastName" +
" FROM Employees" +
" WHERE (LastName LIKE @Find)";
cmd = new SqlCommand(CommandText);
cmd.Connection = con;
cmd.Parameters.Add(
new SqlParameter(
"@Find",
System.Data.SqlDbType.NVarChar,
20,
"LastName"));
cmd.Parameters["@Find"].Value = txtFind.Text;
rdr = cmd.ExecuteReader();
lbFound.Items.Clear();
while(rdr.Read())
{
yourTextBox.Text+= rdr["FirstName"].ToString() +
" " + rdr["LastName"].ToString();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (rdr != null)
rdr.Close();
if (con.State == ConnectionState.Open)
con.Close();
}
The idea is to use regular Ado.Net commands to get the data normally and then put it in a TextBox. Here is the full text of the above sample :
http://www.akadia.com/services/dotnet_data_reader.html[
^]
I hope it helps,
Cheers