Advance Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 827
Number of posts: 1731

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to make a parameter sql statement in vb6 Posted by Cheyenne on 16 Jul 2008 at 5:54 AM
Howdy,
I may need some help/advice for the following issue,
I have a database table with all kinds of sqlstatement in it, in order to show data from the database.
When I use any of the statements by clicking of them, and the executing needs a date then I always have to edit the statement.
I'll tryed to get a parameter in the staement bud always get an error.

for example:
PARAMETERS Begin Date; SELECT * FROM Customers WHERE DateMemberShip > # & Begin & #
this won't work, I almost explored the internet all day, found many items bud nothing specific for VB6, I have read my books, can't find a solution, this is driving me crazy.
Can someone please give me an example or a hint how to solve this
I'll try to acces an Access database using an ADO connection.
Thanks in advance
Cheyenne
Report
Re: how to make a parameter sql statement in vb6 Posted by Barkeeper on 16 Jul 2008 at 7:51 AM
Why are you storing SQL-Statements with Parameters in your Database?
IMHO it's much easier to create the SQL-Statement in your Code and then execute it directly.

Example:
Dim SQLString as String
Dim Begin as Date

'Fill Code in here to get a valid Date

SQLString="SELECT * FROM Customers WHERE DateMemberShip>#" & Begin & "#"

DB.OpenRecordset(SQLString,dbOpenDynaset) <-- This is a Statement from DAO, not ADO but i think you get the Idea

: Howdy,
: I may need some help/advice for the following issue,
: I have a database table with all kinds of sqlstatement in it, in
: order to show data from the database.
: When I use any of the statements by clicking of them, and the
: executing needs a date then I always have to edit the statement.
: I'll tryed to get a parameter in the staement bud always get an
: error.
:
: for example:
: PARAMETERS Begin Date; SELECT * FROM Customers WHERE DateMemberShip
: > # & Begin & #
: this won't work, I almost explored the internet all day, found many
: items bud nothing specific for VB6, I have read my books, can't find
: a solution, this is driving me crazy.
: Can someone please give me an example or a hint how to solve this
: I'll try to acces an Access database using an ADO connection.
: Thanks in advance
: Cheyenne
:

------------------------------------------
Only stupidity of mankind and the universe
are infinite, but i'm not sure concerning
the universe. A. Einstein
Report
Re: how to make a parameter sql statement in vb6 Posted by Cheyenne on 16 Jul 2008 at 10:42 PM
: Why are you storing SQL-Statements with Parameters in your Database?
: IMHO it's much easier to create the SQL-Statement in your Code and
: then execute it directly.
:
: Example:
: Dim SQLString as String
: Dim Begin as Date
:
: 'Fill Code in here to get a valid Date
:
: SQLString="SELECT * FROM Customers WHERE DateMemberShip>#" & Begin &
: "#"
:
: DB.OpenRecordset(SQLString,dbOpenDynaset) <-- This is a Statement
: from DAO, not ADO but i think you get the Idea
:
: : Howdy,
: : I may need some help/advice for the following issue,
: : I have a database table with all kinds of sqlstatement in it, in
: : order to show data from the database.
: : When I use any of the statements by clicking of them, and the
: : executing needs a date then I always have to edit the statement.
: : I'll tryed to get a parameter in the staement bud always get an
: : error.
: :
: : for example:
: : PARAMETERS Begin Date; SELECT * FROM Customers WHERE DateMemberShip
: : > # & Begin & #
: : this won't work, I almost explored the internet all day, found many
: : items bud nothing specific for VB6, I have read my books, can't find
: : a solution, this is driving me crazy.
: : Can someone please give me an example or a hint how to solve this
: : I'll try to acces an Access database using an ADO connection.
: : Thanks in advance
: : Cheyenne
: :
:
: ------------------------------------------
: Only stupidity of mankind and the universe
: are infinite, but i'm not sure concerning
: the universe. A. Einstein

Hello Barkeeper,

at first thanks for the replay, but, I have a programm that is beeing used by someone(s) that doesn't know how to make a sql statement, so I give him (them) a listbox with all kinds of statements and the purpose off them.
When the user select the statement just the date should be filled in to execute the statement, altough that's the idee.
Cheyenne
Report
Re: how to make a parameter sql statement in vb6 Posted by Barkeeper on 17 Jul 2008 at 12:23 AM
: : Why are you storing SQL-Statements with Parameters in your Database?
: : IMHO it's much easier to create the SQL-Statement in your Code and
: : then execute it directly.
: :
: : Example:
: : Dim SQLString as String
: : Dim Begin as Date
: :
: : 'Fill Code in here to get a valid Date
: :
: : SQLString="SELECT * FROM Customers WHERE DateMemberShip>#" & Begin &
: : "#"
: :
: : DB.OpenRecordset(SQLString,dbOpenDynaset) <-- This is a Statement
: : from DAO, not ADO but i think you get the Idea
: :
*snipp*
: :
: : ------------------------------------------
: : Only stupidity of mankind and the universe
: : are infinite, but i'm not sure concerning
: : the universe. A. Einstein
:
: Hello Barkeeper,
:
: at first thanks for the replay, but, I have a programm that is
: beeing used by someone(s) that doesn't know how to make a sql
: statement, so I give him (them) a listbox with all kinds of
: statements and the purpose off them.
: When the user select the statement just the date should be filled in
: to execute the statement, altough that's the idee.
: Cheyenne
:

OK, but that's still not a reason to store the SQL-Statements as procedures in the DB.

Gathering from your words, your offering on your form a List with generic SQL-Statements (e.g. the SQL-Statement as above with after selecting it in the Listbox a Input-Box popping up asking for a valid date). Why not treat the Items in your ListBox just as Strings? After hitting an item in the ListBox your code (to which the user doesn't have access to!!!) proccesses something like this:

Sub ListBox_Click(ByVal Index as Integer)
Dim SQLString as String
Dim InputDate as String 'Or Date - whatever you prefer
    
     SQLString=ListBox.Text
     InputDate=InputBox("Input a valid Date")
     'Fill in some code to validate InputDate such If Not IsDate(InputDate) then DoSomething
     SQLString=SQLString & InputDate
     Set RS=DB.OpenRecordset(SQLString,dbOpendynaset)

End Sub

------------------------------------------
Only stupidity of mankind and the universe
are infinite, but i'm not sure concerning
the universe. A. Einstein
Report
Re: how to make a parameter sql statement in vb6 Posted by ilasabba on 18 Aug 2008 at 6:20 AM
Follow this URL. You may find the answer there. I have explained all about using sql in vb6 in this lesson

http://visualbasic.freetutes.com/learn-vb6-advanced/lesson9/


Report
Re: how to make a parameter sql statement in vb6 Posted by SachinSoni on 26 May 2009 at 5:08 AM
contact me at soni16_sachin@yahoo.co.in
I am a software developer and have good knowledge of Programming in VB-Access.
Report
Re: how to make a parameter sql statement in vb6 Posted by Adekdik on 2 Jun 2009 at 3:26 AM
Try to use DtPicker.
for example, "Select * from Customer where Date > '" & DtPicker.value & "'"



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.