473,396 Members | 1,764 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,396 software developers and data experts.

Calling StoredProcedures with Parameters set with null, gives an e

I get the error 'Procedure 'spBO_HeadlineCreate' expects parameter
'@imageid', which was not supplied' when i call the procedure with the
@imageid=null, but id the @imageid as a diff. value no error occurs.
Here's the code and the storedproc...

-- code
SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection
ConfigurationSettings.AppSettings["cnStrDBAdmin"]); // Create connection.
SqlCommand sqlUpdProg=new SqlCommand ();
sqlUpdProg.CommandType=CommandType.StoredProcedure ;
sqlUpdProg.CommandText="spBO_ProgramSave";
sqlUpdProg.Connection=sqlConnection ;
//Handle the parameters
sqlUpdProg.Parameters.Add("@title", SqlDbType.NVarChar);
sqlUpdProg.Parameters.Add("@imageid", SqlDbType.BigInt);
sqlUpdProg.Parameters.Add("@date", SqlDbType.DateTime);
sqlUpdProg.Parameters.Add("@text", SqlDbType.NText );
sqlUpdProg.Parameters["@title"].Value = _title;
sqlUpdProg.Parameters["@date"].Value = _date;
sqlUpdProg.Parameters["@text"].Value = _body;
if (_imageid!=-1)
sqlUpdProg.Parameters["@imageid"].Value = _imageid;
else
sqlUpdProg.Parameters["@imageid"].Value =null; //error occur
try
{
sqlConnection.Open();
int statusNews = sqlUpdProg.ExecuteNonQuery();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("ERROR: " + ex.ToString());
throw(ex);
}
finally
{
sqlConnection.Close(); //Close the Connection.
}
--code

--storedproc
CREATE PROCEDURE dbo.spBO_ProgramSave
@date smalldatetime,
@title nvarchar(100),
@imageid bigint,
@text ntext
AS
SET NOCOUNT ON
UPDATE dbo.t_programs SET
[date] = @date,
title = @title,
imageid = @imageid,
[text] = @text
GO
--storedproc

i would appreciate any help, thanks a lot
--
Renato /*Portugal*/ Vieira
Nov 16 '05 #1
3 1342
On Thu, 27 Jan 2005 07:41:05 -0800, Renato Vieira wrote:
I get the error 'Procedure 'spBO_HeadlineCreate' expects parameter
'@imageid', which was not supplied' when i call the procedure with the
@imageid=null, but id the @imageid as a diff. value no error occurs.


If you need to indicate null, try passing DBNull.Value instead of null.
--
Tom Porterfield
Nov 16 '05 #2
Hi Renato,

Try setting the imageID parameter value to System.DBNull.Value. This class
differentiates between a null object and an unitialized value (NULL in the
db).

Please reply to this post if this does not work and I will relook at the
problem.

I hope this helps.
-----------------------------
Nov 16 '05 #3

Thank's a lot Brian and Tom, that solution worked.

Be good...
Nov 16 '05 #4

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

Similar topics

4
by: Paul | last post by:
Hi, In SQL Books Online in the section on @@Error it gives the following example: -- Execute the INSERT statement. INSERT INTO authors (au_id, au_lname, au_fname, phone, address, city,...
0
by: Error while executing SP | last post by:
Hi, I am getting an error while executing a sp from Oracle database. Can you let me know what could be the problem? here is the code using(System.Data.OleDb.OleDbConnection cn = new...
4
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
21
by: Joakim Hove | last post by:
Hello, I have implemented a small library with a function a datatype to manage temporary storage, and handle out correctly casted storage. The function to get a double pointer is for instance: ...
1
by: Phil Mc | last post by:
Trying to call a stored proc but some times don't want to have values inserted in some fields. Hi I am rewriting a VBS script which called a stored proc in a SQL server db. The proc takes a...
4
by: Henning M | last post by:
Hej All Im relativ new to VB.net and im trying to collect som device information using cfgmgr32.dll I use - Declare Function GetListLength Lib "cfgmgr32.dll" Alias...
1
by: C#_Beginner | last post by:
I was wondering if someone can help me out. I'm getting the following error: Message: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'GET_RIGHTS2'...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
11
by: premprakashbhati | last post by:
hello sir, goodevening.... iam working on vb6.0 and sql2005. "select max(centreid) from regionmaster where centreid like '" & intBranchPrefix & "%'", DBConnection, adOpenKeyset,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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,...

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.