Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i put CustomerID coming from the DB to a textbox...
Posted
Comments
walterhevedeich 28-Jul-11 22:21pm    
The question is how are you retrieving your data from your DB. It should be pretty straightforward if have done it. Otherwise, a little reading on ADO.Net may help.

Hi,
Try this most simplest one :)

SqlCommand cmd = new SqlCommand("select productid from table where condition", con);
con.Open();
TextBox.Text=cmd.ExecuteScalar().toString();
 
Share this answer
 
Comments
jmpapa 16-Feb-13 5:22am    
What id there are 3 columns to retrieve and datas will be posted to 3 textbox?
txtEmployeeId.Text = dt.Rows[0]["EmployeeId"].ToString();

or use like it.

SqlCommand cmd = new SqlCommand("select * from table where condition", con);
con.Open();
SqlDataReader dtr = cmd.ExecuteReader();
if (dtr.Read())
{
TextBox.Text = dtr["ProductId"].ToString();
}
con.Close();
 
Share this answer
 
v3
Dim connection As String = System.Configuration.ConfigurationManager.AppSettings("Conn")
Using con As New OleDbConnection(connection)
If con.State = ConnectionState.Closed Then con.Open()
Try
sql = " SELECT CustomerID FROM TABLE NAME "
Dim cmd As OleDbCommand
cmd = New OleDbCommand(sql, con)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read Then
If dr("CustomerID") Is DBNull.Value Then
TextBox.Text = ""
Else
TextBox.Text = dr("CustomerID")
End If
End If
Catch ex As Exception
Response.write(ex.Message)
Finally
If con.State = ConnectionState.Open Then con.Close()
con.Dispose()
If Not dr Is Nothing Then
dr.Close()
End If
End Try
End Using
 
Share this answer
 
MyTextBox.Text = myCustomerId.ToString() ( in case it was an int ).
 
Share this answer
 
v2
uses the ADO.NET
Connection DB,
Command sql,
Read myCustomerId into Array or List
and return the result
last,MyTextBox.Text=result
 
Share this answer
 
Comments
Christian Graus 28-Jul-11 22:52pm    
Why on earth would you read an array if you only want to show one result ?
ohkuy 31-Jul-11 22:03pm    
Expansibility,if the result more than one?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900