refer to a form's text box.text inside a SQL clause

  • Thread starter Thread starter giannis
  • Start date Start date
G

giannis

How can i refer to a form's textbox.text inside a SQL clause ?

I know how is that in Access* but at VB i receive error.

* SELECT FIELD1 FROM TABLE1
WHERE TABLE1.FIELD2=[FORMS]![TEXTBOX].[NAME]
 
How can i refer to a form's textbox.text inside a SQL clause ?

I know how is that in Access* but at VB i receive error.

* SELECT FIELD1 FROM TABLE1
WHERE TABLE1.FIELD2=[FORMS]![TEXTBOX].[NAME]


Hi Giannis try this

Dim strwhereclause as string =textbox1.text

SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2= " ' " + strwhereclause
+" ' "

OR

SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2= " ' " + textbox1.text
+" ' "

Thanks

Adam
 
Adamz5 said:
SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2= " ' " + textbox1.text
+" ' "
The query builder change the textbox1.text in textbox1.[text] and thereby
i receive error.
 
You could use String.Format as done in the example code which can easily be
modified to suit your needs

Using command As New OleDbCommand(string.Format("SELECT * from customers
where = {0}",TextBox1.Text), connection)
 
Slight change, left out the field before the equal sign

Using command As New OleDbCommand(string.Format("SELECT * from customers
where SomeField = {0}",TextBox1.Text), connection)

Kevin S Gallagher said:
You could use String.Format as done in the example code which can easily
be modified to suit your needs

Using command As New OleDbCommand(string.Format("SELECT * from customers
where = {0}",TextBox1.Text), connection)



giannis said:
How can i refer to a form's textbox.text inside a SQL clause ?

I know how is that in Access* but at VB i receive error.

* SELECT FIELD1 FROM TABLE1
WHERE TABLE1.FIELD2=[FORMS]![TEXTBOX].[NAME]
 
You're using a query builder in Visual Studio? For what, a strongly typed
dataset, or for setting up a stored procedure? You need to write your query
to take a parameter, and then when you execute it, pass in the string from
the textbox as the parameter.

Robin S.
---------------------------------
giannis said:
Adamz5 said:
SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2= " ' " + textbox1.text
+" ' "
The query builder change the textbox1.text in textbox1.[text] and thereby
i receive error.
 
Dim connection As New OleDbConnection(connectionString)

What must i write as connectionString in this example ?
I use a .mdb Access database.
 
go to your desktop

right-click NEW file = text.
change the file name to test.udl

double click on it; browse to your MDB.. hit apply save.

change the extension from UDL back to text; open with notepad


this will help you to build ANY connection string you ever need. and
it's built into windows
 
I receive the :
Provider=MSDASQL.1;Persist Security Info=False;
Data Source=MS Access Database;Initial Catalog=c:\my.mdb

is this correct ?

The :
Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=c:\my.mdb

is wrong ?
 
dude if the path to your MDB file is wrong; of course you have to
change that path.

Are you an adult???
 
Technically, I provided a solution that will help to build 'any
connection string ever without going to the internet'

lose the training wheels, Robin
 
Back
Top