Is it possible to put this code TextBox1.Text in TextBox2 control ?

Mangore

Member
Joined
Jan 5, 2012
Messages
17
Programming Experience
Beginner
I have Tow TextBoxes . Textbox1.Text= "Hello" Is it possible to put this code TextBox1.Text in TextBox2 control Msgbo(TextBox2>Text) I hope I'm clear
 

Attachments

  • TextBox.JPG
    TextBox.JPG
    4.3 KB · Views: 41
Last edited:
That doesn't really make sense. TextBox1.Text on its own isn't really useful code. Why would you want to do such a thing? Maybe you should provide a FULL and CLEAR explanation of what you're actually trying to achieve. You must have some larger purpose in mind so please explain it because what you've asked to do really is pointless. For a start, why would the user even know that there is a TextBox named TextBox1 on that form? Secondly, what if they they type "Hello" in the second TextBox too? What's supposed to happen then? Etc, etc.
 
That doesn't really make sense. TextBox1.Text on its own isn't really useful code. Why would you want to do such a thing? Maybe you should provide a FULL and CLEAR explanation of what you're actually trying to achieve. You must have some larger purpose in mind so please explain it because what you've asked to do really is pointless. For a start, why would the user even know that there is a TextBox named TextBox1 on that form? Secondly, what if they they type "Hello" in the second TextBox too? What's supposed to happen then? Etc, etc.

I tried to pass string of SQL from Textbox like this
Select Name,Tel,Address from Table1 where Tel = ' Tom '
I wrote this Sql in the TextBox1, not in the code of project so the user can change the condition ..ex: from where Tel = ' Tom '.. to .. where Tel = ' John '
this way succeed with me.
but if I want to do this line didn't succeed
Select Name,Tel,Address from Table1 where Tel = ' & TextBox2.Text & '
Because it consider the TextBox as string not as object
I hope I'm clear
 
Either you're not being clear or else you're trying to do something very simple in a very complicated way. Are you saying that you have a SQL query and you want the user to be able to enter a value to filter by?
 
Yes. I have SQL query: Select Name,Tel,Address from Table1 where Tel = ' & TextBox2.Text & '
and want to write it in the TexTbox
Why ? .. because I want the user to be able to change it
what happen with my query?.. when I write this query :Select Name,Tel,Address from Table1 where Tel = ' Tom ' .....it successd with me
but: the first query.doesn't because it consider the ' & TextBox2.Text & ' as a String not object.
I hope I'm clear now
 
You don't need two TextBoxes for a start. You only need one, for the user to enter the value. The proper way to do this is something like this:
Dim command As New SqlCommand("SELECT C1, C2 FROM T WHERE C3 = @C3")

command.Parameters.AddWithValue("@C3", TextBox1.Text)
For more information, follow the Blog link in my signature and check out my post on Parameters In ADO.NET.
 
I know this way, but it's not that what I want
Take a look to this please

Public Sub Display_DB(ByVal SQL As String)
        Dim dp As New OleDbDataAdapter(SQL, conn)
        Dim Tabl As New DataTable
        dp.Fill(Tabl)
        DataGridView1.DataSource = Tabl
    End Sub

'in Button I'll insert this code
 Display_DB(Me.TextBox4.Text)' I'll write the SQL query in the textbox4

So :
Select Name,Tel,Address from Table1 where Tel = ' Tom ' .....it successd with me
Select Name,Tel,Address from Table1 where Tel = ' & TextBox2.Text & ' it didn't successd with me without showing any error.because as i think it consider the ' & TextBox2.Text & ' as a String not object.
 
Mangore,

You REALLY should do it jmcilhinney's way. If you did, you would not have the issue you are having.
VB.NET:
Dim command as New SqlCommand("SELECT Name, Tel, Address FROM Table1 WHERE Tel = @tel")

command.Parameters.AddWithValue("@tel", TextBox1.Text)


That being said, the reason your Sql statement is not working is because you are not properly telling it where the text ends and the variable begins. (Again, if you did this jmcilhinney's way you would not have this issue.)
VB.NET:
"SELECT Name, Tel, Address FROM Table1 WHERE Tel = '" & TextBox1.Text & "'"
 
Dim command as New SqlCommand("SELECT Name, Tel, Address FROM Table1 WHERE Tel = @tel")
command.Parameters.AddWithValue("@tel", TextBox1.Text)
Oky how to complete the code to load data from db to DGV?
 
I read your article but I'm confusing by make the table carry the data from databse
Dim command As New OleDbCommand("SELECT Name, Tel, Address FROM Table1 WHERE Tel = @tel")
command.Parameters.AddWithValue("@tel", Form1.TextBox4.Text)
Dim Tabl As New DataTable
' I don't know how to set the Tbl to carry the data from database
Form1.DataGridView1.DataSource = Tabl
 
Back
Top