473,804 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a parameter value with spaces to a SQL server procedure.

I'm having trouble passing a variable that contains spaces. If the
variable contains a space I get the following error:

"Applicatio n uses a value of the wrong type for the current operation."

If I pass a variable with out any spaces the procedure executes without
error.

I have a procedure on SQL Server 2000 with the following variable:
Create Procedure Zproc_Demand_Ma trix
@GroupName as nvarchar(25)
etc...

In an Access 2000 adp I have the following:
Public Sub Export_Demand_M atrix(GroupName As String)
Dim cnn As ADODB.Connectio n
Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim fld As ADODB.Field
Dim strGroup As String

Set cnn = CurrentProject. Connection
Set cmd = New ADODB.Command

cmd.ActiveConne ction = cnn
Set rst = New ADODB.Recordset
strGroup = GroupName

cmd.CommandText = "dbo.Zproc_Dema nd_Matrix"
cmd.CommandType = adCmdStoredProc
cmd.Parameters. Append cmd.CreateParam eter("@Group", _
adVarWChar, adParamInput, 4)
cmd.Parameters( "@Group").V alue = strGroup
rst.Open cmd, , adOpenStatic, adLockOptimisti c

etc...

If I run the procedure from SQL Query Analyzer and supply a variable
containing spaces the procedure runs without error. I think I'm
missing something on the MS Access side.

Nov 13 '05 #1
3 8126
whatduck wrote:
I'm having trouble passing a variable that contains spaces. If the
variable contains a space I get the following error:

"Applicatio n uses a value of the wrong type for the current operation."

If I pass a variable with out any spaces the procedure executes without
error.

I have a procedure on SQL Server 2000 with the following variable:
Create Procedure Zproc_Demand_Ma trix
@GroupName as nvarchar(25)
etc...

In an Access 2000 adp I have the following:
Public Sub Export_Demand_M atrix(GroupName As String)
Dim cnn As ADODB.Connectio n
Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim fld As ADODB.Field
Dim strGroup As String

Set cnn = CurrentProject. Connection
Set cmd = New ADODB.Command

cmd.ActiveConne ction = cnn
Set rst = New ADODB.Recordset
strGroup = GroupName

cmd.CommandText = "dbo.Zproc_Dema nd_Matrix"
cmd.CommandType = adCmdStoredProc
cmd.Parameters. Append cmd.CreateParam eter("@Group", _
adVarWChar, adParamInput, 4)
cmd.Parameters( "@Group").V alue = strGroup
rst.Open cmd, , adOpenStatic, adLockOptimisti c

etc...

If I run the procedure from SQL Query Analyzer and supply a variable
containing spaces the procedure runs without error. I think I'm
missing something on the MS Access side.


Try putting single quote delimiters around the value:

strGroup = "'" & GroupName & "'"
--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #2
I've tried single quote delimiters. I also tried "[" & GroupName & "]",
but I still get the same error.

Nov 13 '05 #3
Oop! I had the size for the parameter set to 4. Once I changed that
to a larger number everything worked fine.

Nov 13 '05 #4

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

Similar topics

0
5446
by: Aaron | last post by:
The following code works fine when previewing a Crystal report using ASP, EXCEPT when it gets to a report using a SubReport and its associated parameters. The whole report just comes up blank with this error message: "The Error Message was: Error detected by database DLL.from: Crystal Reports ActiveX Designer". What am I doing wrong in the SubReport section below and how do I properly pass in sproc params to the subreport? Thanks. ...
3
16949
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
39
7684
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
7
4758
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
4
3003
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and pass it to the Db and retrieveing data from a stored procedure, but I can't get the hang of parameters. I have a method where I can get the parameters passed to the sp but it doesn't want to return any results. Here's a copy of my code:
2
2440
by: Robert E. Flaherty | last post by:
I am using System.Data.OracleClient (Oracle Provider for OLE DB 9.2.0.4.0) in an ASP.NET 1.1 app. I am evoking a stored procedure with a number of input parameters and two output parameters, both declared ParametrerDirection.InputOutput. The first of these two output parameters is an integer value. It is the status of the running of the stored procedure. It is working fine. The second parameter is designed to return a message from...
11
8134
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
4
2768
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx to a stored procedure on the details2.aspx page. I can successfully pass the values from the listbox control to a
1
2656
by: jkeel | last post by:
If I try to Update a record with the following code using a stored procedure I get an error: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:stellentConnectionString %>" SelectCommand="spWC_Adjusters" SelectCommandType="StoredProcedure" InsertCommand="spWC_Adjusters_Insert " InsertCommandType="StoredProcedure" UpdateCommand="spWC_Adjusters_Update"
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
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...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
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...
0
6861
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
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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

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.