473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error message accessing stored proc with C#

Jay
I hope this is the correct place to post this.

I'm using a stored procedure to simply look up and return a value from a
database. The db key is an integer, everything else is varchar. The stored
proc is:
CREATE procedure SP_IMAGE_NAME(
@MAT_ID varchar(13),
@TYPE varchar(1),
@IMAGE_NM varchar(100) OUTPUT
) as
begin

SELECT @IMAGE_NM = FileName FROM IPSAvailableIma gesFinal
WHERE (MaterialNumber = @MAT_ID) AND (type = @TYPE)
RETURN @IMAGE_NM
end
GO

But when I run it using C# ASP.NET, I get this error:
Syntax error converting the varchar value '53_8663_69_MU_ LSLV_HG' to a
column of data type int.

On my command.Execute NonQuery() call. Any ideas?

My ASP.NET code is below just in case . . . Thanks in advance.

--
Thanks,
Jay Allen

public string ImageName(strin g Code)
{
string Image_Name;
string connectionStrin g = CommonAppSettin gs.SqlConnectio nString;
System.Data.Sql Client.SqlConne ction connection = new
System.Data.Sql Client.SqlConne ction(connectio nString);
connection.Open ();

System.Data.Sql Client.SqlComma nd command = new
System.Data.Sql Client.SqlComma nd();
command.Connect ion = connection;

command.Command Text= "SP_IMAGE_NAME" ;
command.Command Type = CommandType.Sto redProcedure;

System.Data.Sql Client.SqlParam eter param;

param = command.Paramet ers.Add("@IMAGE _NM", SqlDbType.VarCh ar);
param.Direction = ParameterDirect ion.Output;
param.Size = 100;

param = command.Paramet ers.Add("@MAT_I D", SqlDbType.VarCh ar);
param.Direction = ParameterDirect ion.Input;
param.Size = 13;
param.Value = Code;

param = command.Paramet ers.Add("@Type" , SqlDbType.VarCh ar);
param.Direction = ParameterDirect ion.Input;
param.Size = 1;
param.Value = "1";

command.Execute NonQuery();
//return command.Paramet ers["@IMAGE_NM"].Value.ToString ();
param = command.Paramet ers["@IMAGE_NM"];
Image_Name = param.Value.ToS tring();
return Image_Name;
connection.Clos e();
}

Aug 9 '05 #1
1 1869
Hi Jay,
You should not return varchar variables from SP. Skip "RETURN @IMAGE_NM" line.
--
Leon Langleyben
MCSD
http://dotnetjunkies.com/WebLog/leon/
"Jay" wrote:
I hope this is the correct place to post this.

I'm using a stored procedure to simply look up and return a value from a
database. The db key is an integer, everything else is varchar. The stored
proc is:
CREATE procedure SP_IMAGE_NAME(
@MAT_ID varchar(13),
@TYPE varchar(1),
@IMAGE_NM varchar(100) OUTPUT
) as
begin

SELECT @IMAGE_NM = FileName FROM IPSAvailableIma gesFinal
WHERE (MaterialNumber = @MAT_ID) AND (type = @TYPE)
RETURN @IMAGE_NM
end
GO

But when I run it using C# ASP.NET, I get this error:
Syntax error converting the varchar value '53_8663_69_MU_ LSLV_HG' to a
column of data type int.

On my command.Execute NonQuery() call. Any ideas?

My ASP.NET code is below just in case . . . Thanks in advance.

--
Thanks,
Jay Allen

public string ImageName(strin g Code)
{
string Image_Name;
string connectionStrin g = CommonAppSettin gs.SqlConnectio nString;
System.Data.Sql Client.SqlConne ction connection = new
System.Data.Sql Client.SqlConne ction(connectio nString);
connection.Open ();

System.Data.Sql Client.SqlComma nd command = new
System.Data.Sql Client.SqlComma nd();
command.Connect ion = connection;

command.Command Text= "SP_IMAGE_NAME" ;
command.Command Type = CommandType.Sto redProcedure;

System.Data.Sql Client.SqlParam eter param;

param = command.Paramet ers.Add("@IMAGE _NM", SqlDbType.VarCh ar);
param.Direction = ParameterDirect ion.Output;
param.Size = 100;

param = command.Paramet ers.Add("@MAT_I D", SqlDbType.VarCh ar);
param.Direction = ParameterDirect ion.Input;
param.Size = 13;
param.Value = Code;

param = command.Paramet ers.Add("@Type" , SqlDbType.VarCh ar);
param.Direction = ParameterDirect ion.Input;
param.Size = 1;
param.Value = "1";

command.Execute NonQuery();
//return command.Paramet ers["@IMAGE_NM"].Value.ToString ();
param = command.Paramet ers["@IMAGE_NM"];
Image_Name = param.Value.ToS tring();
return Image_Name;
connection.Clos e();
}

Aug 9 '05 #2

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

Similar topics

0
1280
by: Rick | last post by:
I wrote a medium length stored proc that uses both temp tables and one cursor. I compiled and it ran fine. However, we reboot our machine every weekend, and on Mondays the stored proc gets the following errors : Infinite loops on cursors (can't fetch the next record. Gets stuck on one record) AND
1
2954
by: Jon LaRosa | last post by:
Hi all - I have a web application and I want to be able to do some basic error handling. For example, here is one error I would like to catch and display in a useful way for the user: ----------------- Microsoft OLE DB Provider for ODBC Drivers error '80040e14' UPDATE statement
1
4336
by: Jen S | last post by:
I feel like I'm missing something obvious here, but I'm stumped... I have a stored procedure with code that looks like: INSERT INTO MyTableA ( ...fields... ) VALUES (...values...) IF (@@ERROR <> 0) BEGIN ROLLBACK TRANSACTION; RAISERROR('An error occurred in the stored proc.', 16, 1);
11
3490
by: ColdCanuck | last post by:
Greetings! I am VERY new to DB2 but not Orable, Sybase and SQL Server. I am trying to call a stored procedure via VB 6 and ADO/OLEDB. But when I try to execute
0
2096
by: Mike Thomas | last post by:
This one must be very simple. I am trying to run an SQL Serv 7.0 stored proc from a VBA module in an Access 2000 app. This stored proc runs fine when I remove the parameters from the stored proc and from the CommandText string below, but when I run it as is I get the error SQL Serv Syntax Error or Access Violation on the "Execute" line. _ContactFetchLike 'Thom%' also works when I run it from the Query Analyser.
9
2841
by: kangaroo | last post by:
Hi guys, when we run a stored proc and it results into an unhandled error, the error message returned by db2 udb does not contain a line number that caused an error. This makes it pretty difficult to debug those procs. Line number have always been there in Oracle messages. When I Googled on this, I saw some people showing DB2 Stored Proc error messages with line numbers in them (like LINE NUMBER=1285), which makes me believe that...
1
273
by: Jay | last post by:
I hope this is the correct place to post this. I'm using a stored procedure to simply look up and return a value from a database. The db key is an integer, everything else is varchar. The stored proc is: CREATE procedure SP_IMAGE_NAME( @MAT_ID varchar(13), @TYPE varchar(1), @IMAGE_NM varchar(100) OUTPUT ) as
0
2446
by: jeethsu | last post by:
Hi, I have Java application running on Websphere Application Server 6.0 This application connects to Mainframe DB2 using CLI type 2 driver. The application uses websphere connection pool mechanism. I have stored procedures which are called from the application and one particular stored procedure call throws the below error: SystemErr R SQL exception: com.ibm.websphere.ce.cm.StaleConnectionException: CLI0108E Communication link...
2
10560
by: lltong | last post by:
I have db2 ESE v9 fix pak 2 installed on red hat linux kernel 2.6. When I use db2 load facility even with 1 row to be inserted, I see this error message: SQL2044N An error occurred while accessing a message queue. Reason code: "3". I read some post online about SQL2044 and learned sometimes it is about the linux kernel parameter not being set up correctly. But it is not my case here. I've got the big enough msgmni: # For DB2
0
8995
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
9561
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
9381
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
9332
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
9254
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
8252
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
4608
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...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
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.