Need Help passing Parameters to SQL query in a VB dataenviroment 
Author Message
 Need Help passing Parameters to SQL query in a VB dataenviroment


Thanks in advance for any and all help.

Mike

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Wed, 16 Jul 2003 02:03:32 GMT  
 Need Help passing Parameters to SQL query in a VB dataenviroment
Would be easy to pass .... in Code   : ))

Dim MyVar as string, strSql as string
Dim mCmd as ADODB.Command
Dim mrstContact as ADODB.Recordset

    MyVar = text1.text
    strSql = "SELECT * FROM tblMyTable" _
                & "WHERE MyField = " & MyVar & ""

    Set mCmd = New ADODB.Command
        mCmd.ActiveConnection = Conn
        mCmd.CommandType = adCmdText
        mCmd.CommandText = strSql

    Set mrstContact = New ADODB.Recordset
        mrstContact.CursorLocation = adUseClient
        mrstContact.Open mCmd, , adOpenStatic, adLockOptimistic

This above is for access database and JET 4.0 connection although will
do same using SqlServer.... but stored procedure is better......

If you need a single record from SqlServer just pass a parameter...

        Set Cmd = New ADODB.Command
        Cmd.ActiveConnection = Conn
        Cmd.CommandText = "ContactsList2"
        Cmd.CommandType = adCmdStoredProc

        ContactsList.CursorLocation = adUseClient
        ContactsList.Open Cmd, , adOpenStatic, adLockReadOnly

For SqlServer and Stored procedure.....

Just set your connection..... and off you go .......this is for sqlserver
nt integrated security

    Set Conn = New ADODB.Connection
    Conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;"
_
    & "Persist Security Info=False;Initial Catalog=ZodiacSql;Data
Source=192.168.2.1"

    Conn.Open

Regards

VOrtex


I am trying to create a program to search a SQL database by last name.  I
have a form with a text box, and search button.  I created a connection to
the database through a dataenviroment and then created a command.  The
command is a SQL statement that quries the database for any records matching
the last name entered in the text box.  In the query I told it to give me

for the last name, but when I try to run the program it says I need to

parameter on the parameter tab in the command properties window.  I tried
putting the line 'Parameters pLastName text; then the SQL code for the
querey with the new parameter but it still won't work.  How do I pass the
value of a text box to a SQL query?  Am I going about this all wrong?

Thanks in advance for any and all help.

Mike

*** Sent via Developersdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 16 Jul 2003 07:05:18 GMT  
 Need Help passing Parameters to SQL query in a VB dataenviroment
In the dataenvironment you need to specify the parameter as ? then you can
go to the parameters tab and set up the parameter (type, size etc)

HTH

Nathan



Thu, 17 Jul 2003 19:28:40 GMT  
 Need Help passing Parameters to SQL query in a VB dataenviroment
See http://msdn.microsoft.com/library/periodic/period00/caching.htm for
information on creating parameterized queries.

Kirk Allen Evans
http://www.vbdna.net


I am trying to create a program to search a SQL database by last name.  I
have a form with a text box, and search button.  I created a connection to
the database through a dataenviroment and then created a command.  The
command is a SQL statement that quries the database for any records matching
the last name entered in the text box.  In the query I told it to give me

for the last name, but when I try to run the program it says I need to

parameter on the parameter tab in the command properties window.  I tried
putting the line 'Parameters pLastName text; then the SQL code for the
querey with the new parameter but it still won't work.  How do I pass the
value of a text box to a SQL query?  Am I going about this all wrong?

Thanks in advance for any and all help.

Mike

*** Sent via Developersdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 20 Jul 2003 23:19:13 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. passing parameters to a sql query from a vb form

2. Need help passing query parameters in a url

3. Help with SQL parameter query needed!

4. Passing Parameters to stored parameter queries using VB 5's Data Controls

5. Stored, Pass Through, Parameter Query on Access 2k and SQL Server 7

6. Passing Parameters to SQL Query in a contols data source

7. SQL: Passing parameters to a stored query

8. Help needed: Setting parameters in parameter queries

9. Help needed: Setting parameters in parameter queries

10. passing array as a parameter to a SQL query

11. passing parameters in 2nd SQL query

12. Help Passing sql query result to VB

 

 
Powered by phpBB® Forum Software