473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 IPSAvailableImagesFinal
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.ExecuteNonQuery() call. Any ideas?

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

--
Thanks,
Jay Allen

public string ImageName(string Code)
{
string Image_Name;
string connectionString = CommonAppSettings.SqlConnectionString;
System.Data.SqlClient.SqlConnection connection = new
System.Data.SqlClient.SqlConnection(connectionStri ng);
connection.Open();

System.Data.SqlClient.SqlCommand command = new
System.Data.SqlClient.SqlCommand();
command.Connection = connection;

command.CommandText= "SP_IMAGE_NAME";
command.CommandType = CommandType.StoredProcedure;

System.Data.SqlClient.SqlParameter param;

param = command.Parameters.Add("@IMAGE_NM", SqlDbType.VarChar);
param.Direction = ParameterDirection.Output;
param.Size = 100;

param = command.Parameters.Add("@MAT_ID", SqlDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Size = 13;
param.Value = Code;

param = command.Parameters.Add("@Type", SqlDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Size = 1;
param.Value = "1";

command.ExecuteNonQuery();
//return command.Parameters["@IMAGE_NM"].Value.ToString();
param = command.Parameters["@IMAGE_NM"];
Image_Name = param.Value.ToString();
return Image_Name;
connection.Close();
}

Aug 9 '05 #1
1 1842
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 IPSAvailableImagesFinal
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.ExecuteNonQuery() call. Any ideas?

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

--
Thanks,
Jay Allen

public string ImageName(string Code)
{
string Image_Name;
string connectionString = CommonAppSettings.SqlConnectionString;
System.Data.SqlClient.SqlConnection connection = new
System.Data.SqlClient.SqlConnection(connectionStri ng);
connection.Open();

System.Data.SqlClient.SqlCommand command = new
System.Data.SqlClient.SqlCommand();
command.Connection = connection;

command.CommandText= "SP_IMAGE_NAME";
command.CommandType = CommandType.StoredProcedure;

System.Data.SqlClient.SqlParameter param;

param = command.Parameters.Add("@IMAGE_NM", SqlDbType.VarChar);
param.Direction = ParameterDirection.Output;
param.Size = 100;

param = command.Parameters.Add("@MAT_ID", SqlDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Size = 13;
param.Value = Code;

param = command.Parameters.Add("@Type", SqlDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Size = 1;
param.Value = "1";

command.ExecuteNonQuery();
//return command.Parameters["@IMAGE_NM"].Value.ToString();
param = command.Parameters["@IMAGE_NM"];
Image_Name = param.Value.ToString();
return Image_Name;
connection.Close();
}

Aug 9 '05 #2

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

Similar topics

0
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...
1
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: ...
1
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...
11
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
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...
9
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...
1
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...
0
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.