473,732 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling parameterised views from VB

I'd really appreciate your help creating a parameterised view in SQL
Server, which I can then invoke from VB5. I'm using DAO and ODBC to
connect to SQL Server 2000.

I can open Tables and Views, but can't find how to create or use a
"query" parameter. If I use the "?" (in the SQL Enterprise manager
View design mode), the syntax checker verifies the query ok, but I
then get the message "Parameters cannot be used in this query type".
It doesn't like the %var% terminology at all here.

I am sure I could build the full query in VB and save it to the Server
"on-the-fly", but this partly defeats the object, doesn't it?

I could really do with a couple of pointers: (a) how to define the
view/query in Ent Manager and (b) how to invoke it from VB, supplying
the parameter.

Thanks ever so in anticipation.

Phil
Jul 20 '05 #1
9 5911
Phil Sowden (ph********@dat aservicesltd.co .uk) writes:
I'd really appreciate your help creating a parameterised view in SQL
Server, which I can then invoke from VB5. I'm using DAO and ODBC to
connect to SQL Server 2000.

I can open Tables and Views, but can't find how to create or use a
"query" parameter. If I use the "?" (in the SQL Enterprise manager
View design mode), the syntax checker verifies the query ok, but I
then get the message "Parameters cannot be used in this query type".
It doesn't like the %var% terminology at all here.

I am sure I could build the full query in VB and save it to the Server
"on-the-fly", but this partly defeats the object, doesn't it?

I could really do with a couple of pointers: (a) how to define the
view/query in Ent Manager and (b) how to invoke it from VB, supplying
the parameter.


Views cannot be parameterized in SQL Server. However there are table-valued
functions, which are about the same thing. Example:

CREATE FUNCTION myorders (@custid nchar(5)) RETURNS TABLE AS
RETURN (SELECT * FROM Northwind..Orde rs WHERE CustomerID = @custid)
go
SELECT * FROM myorders(N'ALFK I')
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Thanks very much indeed for your help, Erland.

I had tried this, amongst many other things. However, I didn't realise
I'd got it right, as I couldn't work out how to populate a VB recordset
object from an SQL function.

I normally (in Access) open a database object, then use something like:

lsSQL = "Select * from Northwind.Order s WHERE CustomerID = " &
llCustID
Set lrsOrders = gdbMain.OpenRec ordset(lsSQL)
lrsOrders.MoveF irst

where:
gdbMain is a globally-defined database object
lrsOrders is a locally-defined recordset object

This second part of my question probably belongs in the VB or Access
newsgroups, I'm sure, but maybe you can help again, Erland?

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Phil (ph********@nos pam.dataservice sltd.co.uk) writes:
I had tried this, amongst many other things. However, I didn't realise
I'd got it right, as I couldn't work out how to populate a VB recordset
object from an SQL function.

I normally (in Access) open a database object, then use something like:

lsSQL = "Select * from Northwind.Order s WHERE CustomerID = " &
llCustID
Set lrsOrders = gdbMain.OpenRec ordset(lsSQL)
lrsOrders.MoveF irst

where:
gdbMain is a globally-defined database object
lrsOrders is a locally-defined recordset object


So to call the table function you would say:

lsSQL = "Select * from myorders(" & llCustID & ")"


--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4
That's brilliant, thanks, Erland. I've applied that example to my
system and got it to work fine within SQL Server now.

However, when I try:
lsSQL = "Select * from FindCust('07940 437220')"
Set lrsTemp = gdbSparc.OpenRe cordset(lsSQL)

...in VB, I get "Error 3131 - Syntax Error in FROM clause". It's as if
VB doesn't recognise the function exists at all?

The identical code works fine (as a View) within SQL Server (n.b. the
customer reference I'm using is a 14 character nvarchar field).

I'm sorry to be such a novice! I also realise that this may not be the
correct forum - but it may be that you are able to help.

Thanks once again,

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
Phil (ph********@nos pam.dataservice sltd.co.uk) writes:
That's brilliant, thanks, Erland. I've applied that example to my
system and got it to work fine within SQL Server now.

However, when I try:
lsSQL = "Select * from FindCust('07940 437220')"
Set lrsTemp = gdbSparc.OpenRe cordset(lsSQL)

..in VB, I get "Error 3131 - Syntax Error in FROM clause". It's as if
VB doesn't recognise the function exists at all?


That right. In fact VB does not know anything about SQL at all. I don't
know what this OpenRecordset is, but that much I can tell that the
error message you get does not come from SQL Server. And since VB
does not SQL, it must be someother data source you are querying. Didn't
you mention Access? Well, I don't know anything about Access, so...

--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #6
Cool. Thanks again for your help, Erland, I'm sure I'll resolve it
shortly.

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7
In article <40************ *********@news. frii.net>, Phil <ph********@nos pam.dataservice sltd.co.uk> wrote:
That's brilliant, thanks, Erland. I've applied that example to my
system and got it to work fine within SQL Server now.

However, when I try:
lsSQL = "Select * from FindCust('07940 437220')"
Set lrsTemp = gdbSparc.OpenRe cordset(lsSQL)

...in VB, I get "Error 3131 - Syntax Error in FROM clause". It's as if
VB doesn't recognise the function exists at all?

The identical code works fine (as a View) within SQL Server (n.b. the
customer reference I'm using is a 14 character nvarchar field).

I'm sorry to be such a novice! I also realise that this may not be the
correct forum - but it may be that you are able to help.

Thanks once again,

Phil

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

You have a table named FindCust('07940 437220') in your database? Who came
up with an impossible to remember name like that?
Jul 20 '05 #8
Rico,

Thanks for your interest.

If you're able to tell me how to design a parameterised SQL View and
call it from VB, I'd be ecstatic! I'm sure I can fix that function name
quite easily!

The SQL table is called "Cust", but I had to create a table-type
function to return a view / query of selected records with a parameter.
The "FindCust() " function returns a recordset of customers found for the
parameter value given. I thought the name was quite meaningful,
actually!

The call you're looking at is my failed attempt to call that same
function from within VB (version 5, using DAO with ODBC connection to
SQL Server).

Ideas most welcome....!

Phil
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #9
Phil (ph********@nos pam.dataservice sltd.co.uk) writes:
The call you're looking at is my failed attempt to call that same
function from within VB (version 5, using DAO with ODBC connection to
SQL Server).


Aha, so that OpenRowset is DAO? Now, I don't know DAO, and it might be
that DAO is itself trying interpreting the SQL statement. In such case
you are probably out of luck, because DAO is too old to know about
table-value functions added to SQL2000. I would guess that DAO is not
equipped to handle that. But if it's ODBC which performs the syntax
check, then it's only a matter of getting version 2.6 or later of the
MDAC. They are available at:
http://www.microsoft.com/downloads/d...DisplayLang=en
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
15234
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental differences between a view and a query, or rather, when it is more appropriate to use one vs. the other. It seems to me that most select queries can be implemented as views, and I can't see the downside to doing so.
2
1671
by: John | last post by:
Hi New to sql server. using beta2 2005. What is the way to implement parameterised queries? I need the queries to be updatable as these would work as recordsets that vb.net forms will be bound to for data entry. Thanks Regards
3
10179
by: KemperR | last post by:
Hello Experts outhere, may be someone can tell me whats going wrong with my ADOX trial. I have an Access 2002 database with some tables and queries (views) The code listed below works well up to the point where I want to add the new view to the views collection. I get Runtime error 3001 which is telling me "Arguments are of wrong type,are out of acceptable range or conflict with one another"
5
10707
by: Tim Marsden | last post by:
Hello, I am building a parameterised query in vb.net for execution against a SQL server database. I am using a OLEDB command and OLEDB parameters. If one of the parameters is a date I sometimes experience a problem in the interpretation of the format. I populate the parameter value from a user input text box. I am in the UK so the use inputs in the format dd/mm/yy. I know SQL user the US format of mm/dd/yy.
15
3069
by: rod.weir | last post by:
Fellow database developers, I would like to draw on your experience with views. I have a database that includes many views. Sometimes, views contains other views, and those views in turn may contain views. In fact, I have some views in my database that are a product of nested views of up to 6 levels deep! The reason we did this was. 1. Object-oriented in nature. Makes it easy to work with them.
0
1229
by: ken | last post by:
Hi, I connected Access 2003 to SQL express 2005. My question is in access if I have a query, I can put in the criteria a function to return some kind of criteria statement. I can also redefine the query in some event procedure in a form using VBA. Now that I'm using SQL, I want to do something similar with views. I have a list box that I want filtered on a form. The values for the list box come from a view. I want to filter this list...
2
1584
by: B.r.K.o.N.j.A | last post by:
I'm using mysql 4.1 and php5.0.4. Since (AFAIK) this version of mysql supports parameterised queries, is there a way to accomplish that using mysql_... functions (looks like mysql client library is unaware of this feature), I need it to avoid sql injection in a "right" way... :)) -- B.r.K.o.N.j.A = Bionic Robotic Knight Optimized for Nocturnal Judo and Assasination
5
1513
by: John | last post by:
Hi I have a parameterised query for a report like this; PARAMETERS Event_ID Short; SELECT DISTINCTROW Events., ... FROM Events WHERE (((Events.)=)); Now I am trying to run the report while passing the parameter value like
1
1593
by: DebGuria | last post by:
I have written a managed C++ dll. I have to use that dll from C#, VB .NET and VB. It has got a parameterised propetyfor the very specific requirement. For example get_Pie(float f). When I am using that dll from another Managed C++ application, VS 2003/2005 IDE is displaying one property and one method for that. i.e. displaying "get_Pie" as method and "Pie" as property. But when I am using that dll from C#, it is displaying only method...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.