Groups | Blog | Home
all groups > vb.net > february 2007 >

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


Adamz5
2/16/2007 7:34:58 AM
[quoted text, click to view]


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
Kevin S Gallagher
2/16/2007 8:36:00 AM
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)



[quoted text, click to view]

Kevin S Gallagher
2/16/2007 8:39:14 AM
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)

[quoted text, click to view]

RobinS
2/16/2007 8:41:02 AM
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.
---------------------------------
[quoted text, click to view]

pfc_sadr NO[at]SPAM hotmail.com
2/16/2007 1:11:03 PM
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




[quoted text, click to view]

giannis
2/16/2007 5:03:24 PM
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]

giannis
2/16/2007 6:00:35 PM
[quoted text, click to view]
The query builder change the textbox1.text in textbox1.[text] and thereby
i receive error.

giannis
2/16/2007 7:01:43 PM
Dim connection As New OleDbConnection(connectionString)

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

RobinS
2/16/2007 10:37:17 PM
Did you try it?

A good place to look for help with connection strings is
http://www.connectionstrings.com


Robin S.
---------------------------
[quoted text, click to view]

giannis
2/17/2007 12:00:00 AM
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 ?

PFC Sadr
2/19/2007 2:23:59 PM
dude if the path to your MDB file is wrong; of course you have to
change that path.

Are you an adult???




[quoted text, click to view]

PFC Sadr
2/19/2007 2:24:46 PM
Technically, I provided a solution that will help to build 'any
connection string ever without going to the internet'

lose the training wheels, Robin






[quoted text, click to view]

AddThis Social Bookmark Button