dbTalk Databases Forums  

sql query in vb

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss sql query in vb in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
GANESH NAIDU
 
Posts: n/a

Default sql query in vb - 03-09-2006 , 06:07 AM






i need help in sql query my coding is as under

Dim MRUNYEAR As String
MRUNYEAR = "0405"
Set fgrs = New Recordset
fgrs.Open "select CT3HDR.CT3ID, CT3HDR.CT3NO,
format(CT3HDR.ct3date,'dd/mm/yyyy'), suppmast.suppname FROM CT3HDR INNER
JOIN suppmast ON CT3HDR.suppID=suppmast.suppid WHERE
CT3HDR.RUNYEAR=MRUNYEAR ORDER BY CT3HDR.CT3NO", db, dbopenstatic,
adLockOptimistic

i am receiving error "no value given for one or more required parameter"

if i give '0405' directly in the query than it is running fine. so how
to give mrunyear variable in the query.

thanks,
ganesh



*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #2  
Old   
Jens
 
Posts: n/a

Default Re: sql query in vb - 03-09-2006 , 06:51 AM






Should be more something like:

....CT3HDR.RUNYEAR=" & MRUNYEAR & "ORDER BY ...

HTH, jens Suessmeyer.


Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: sql query in vb - 03-09-2006 , 05:18 PM



GANESH NAIDU (ganeznaidu (AT) yahoo (DOT) com) writes:
Quote:
i need help in sql query my coding is as under

Dim MRUNYEAR As String
MRUNYEAR = "0405"
Set fgrs = New Recordset
fgrs.Open "select CT3HDR.CT3ID, CT3HDR.CT3NO,
format(CT3HDR.ct3date,'dd/mm/yyyy'), suppmast.suppname FROM CT3HDR INNER
JOIN suppmast ON CT3HDR.suppID=suppmast.suppid WHERE
CT3HDR.RUNYEAR=MRUNYEAR ORDER BY CT3HDR.CT3NO", db, dbopenstatic,
adLockOptimistic

i am receiving error "no value given for one or more required parameter"

if i give '0405' directly in the query than it is running fine. so how
to give mrunyear variable in the query.
I'm a little surprised over the error; I would rather expect something
about an unknown column.

You would say

RUNYEAR = ?

And then you should use the Command object to define the query, and
the .CreateParameter method to add the parameter.

By the way, judging from the appearance of the Format function, it
appears that you are using Access. This is a newsgroup for SQL
Server, so you may not get the best advice here.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.