472,974 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,974 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 1822
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.