Results 1 to 9 of 9

Thread: Question Parametized Queries

  1. #1

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Question Parametized Queries

    Reference this thread from yesterday.

    I'm trying to write my first parametized INSERT query. I have an ADODB.Command oject defined as cn. However, I'm getting no intellisense listings for ComandText or Parameters, etc. A snippet of the code from the referenced thread is
    VB Code:
    1. sSQL = "INSERT INTO movieInfo (title, actor, producer, comment) VALUES (?,?,?,?)
    2.  
    3. objCommand.CommandText = sSQL
    4. objCommand.CommandType = adCommandText
    5. objCommand.Parameters.Add objCommand.CreateParameter("title",advarchar,50, txtTitle.Text)
    6. objCommand.Parameters.Add objCommand.CreateParameter("actor",advarchar,50, txtactor.Text)
    7. objCommand.Parameters.Add objCommand.CreateParameter("producer",advarchar,50, txtproducer.Text)
    8. objCommand.Parameters.Add objCommand.CreateParameter("comment",advarchar,50, txtComment.Text)
    9.  
    10. objCommand.Execute
    Although I can't find where objCommand is declared in that thread, I assumed it was as ADODB.Connection. If not, then what is it? What do I need for the .Parameters.Add and .CommandType, etc?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Question Parametized Queries

    You've got it backwards - objCommand should be an ADODB.Command, and cn should be a connection (tho you dont seem to be using it).

  3. #3

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Question Parametized Queries

    Quote Originally Posted by si_the_geek
    You've got it backwards - objCommand should be an ADODB.Command, and cn should be a connection (tho you dont seem to be using it).
    Now, I'm only semi confused.

    So, I need a variable, call is adoCmd declared as ADODB.Command, and that is going to give me all of the things I need to build the query (I just tested it, and that works fine - thanks si_the_geek )

    However, were I to not use a parametized (how do you spell that word anyway? ) query, I would write a standard INSERT INTO table (blah, blah) VALUES (text1.text, text2.text) and I would execute this using the execute method of the connection object: cn.Execute ssql

    I can execute an INSERT query with a command object????
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Question Parametized Queries

    Sean - Yes you can....

    In your referenced thread, objCommand is an ADODB.Command object (hence the Command part of objCommand). The other assumption in that thread is that you also set the objCommand.ActiveConnection to a valid, open connection before performing the execute.

    If I can find a decent one, I'll post a real-world example of how this is all done.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Question Parametized Queries

    Quote Originally Posted by techgnome
    If I can find a decent one, I'll post a real-world example of how this is all done.

    -tg
    That would be VERY cool. In addition to the security aspects that you and Shuja Ali pointed out in the other thread, the INSERT I have to do deals with 71 fields. It would be a whole heck of a lot easier to put 71 question marks in the VALUES clause that putting 71 textbox names in the VALUES clause and hope you got the right number, in the right order, with the right puncutation.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Question Parametized Queries

    Darn right it would be.... I'll get one as soon as I can...
    I won't forget...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Question Parametized Queries

    Quote Originally Posted by techgnome
    Darn right it would be.... I'll get one as soon as I can...
    I won't forget...

    -tg
    Did you ever get a chance to put together some examples of using parameteized queries for UPDATES, DELETES, INSERTS and/or SELECTS?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Question Parametized Queries

    Quote Originally Posted by SeanK
    Did you ever get a chance to put together some examples of using parameteized queries for UPDATES, DELETES, INSERTS and/or SELECTS?
    He is putting together something for the codebank.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Question Parametized Queries

    It's been a slow painful process... life keeps getting in the way, it is certanly on my to do list.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width