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

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]
 
A

Adamz5

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
 
G

giannis

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.
 
K

Kevin S Gallagher

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)
 
K

Kevin S Gallagher

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]
 
R

RobinS

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.
 
G

giannis

Dim connection As New OleDbConnection(connectionString)

What must i write as connectionString in this example ?
I use a .mdb Access database.
 
P

pfc_sadr

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
 
G

giannis

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

PFC Sadr

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

Are you an adult???
 
P

PFC Sadr

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

lose the training wheels, Robin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top