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

Home Posts Topics Members FAQ

Calling StoredProcedure s with Parameters set with null, gives an e

I get the error 'Procedure 'spBO_HeadlineC reate' 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.Sql Client.SqlConne ction
ConfigurationSe ttings.AppSetti ngs["cnStrDBAdm in"]); // Create connection.
SqlCommand sqlUpdProg=new SqlCommand ();
sqlUpdProg.Comm andType=Command Type.StoredProc edure;
sqlUpdProg.Comm andText="spBO_P rogramSave";
sqlUpdProg.Conn ection=sqlConne ction ;
//Handle the parameters
sqlUpdProg.Para meters.Add("@ti tle", SqlDbType.NVarC har);
sqlUpdProg.Para meters.Add("@im ageid", SqlDbType.BigIn t);
sqlUpdProg.Para meters.Add("@da te", SqlDbType.DateT ime);
sqlUpdProg.Para meters.Add("@te xt", SqlDbType.NText );
sqlUpdProg.Para meters["@title"].Value = _title;
sqlUpdProg.Para meters["@date"].Value = _date;
sqlUpdProg.Para meters["@text"].Value = _body;
if (_imageid!=-1)
sqlUpdProg.Para meters["@imageid"].Value = _imageid;
else
sqlUpdProg.Para meters["@imageid"].Value =null; //error occur
try
{
sqlConnection.O pen();
int statusNews = sqlUpdProg.Exec uteNonQuery();
}
catch (Exception ex)
{
System.Diagnost ics.Debug.Write Line("ERROR: " + ex.ToString());
throw(ex);
}
finally
{
sqlConnection.C lose(); //Close the Connection.
}
--code

--storedproc
CREATE PROCEDURE dbo.spBO_Progra mSave
@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 1358
On Thu, 27 Jan 2005 07:41:05 -0800, Renato Vieira wrote:
I get the error 'Procedure 'spBO_HeadlineC reate' 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.V alue. 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
23499
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, state, zip, contract) values (@au_id,@au_lname,@au_fname,@phone,@address,
0
1914
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 System.Data.OleDb.OleDbConnection()) { cn.ConnectionString="Provider=OraOLEDB.Oracle;Password=STORED_OBJ;User ID=STORED_OBJ;Data Source=PDCDGL1.NA.HPFS.COM;Extended Properties=;Persist Security Info=False;PLSQLRSet=1;"; cn.Open(); //String strProcName =...
4
10690
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
21
3598
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: double * work_get_double(work_type *work, size_t size) {} Now, if the work area is not sufficiently large, the function fails,
1
2339
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 number of values both char and floats. Sometime it is a requirement that the stored proc will not be given a values for some of the floats.
4
3345
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 "CM_Get_Device_ID_List_SizeA" (ByRef pulLen As Integer, ByVal pszFilter As Integer, ByVal UlFlags As Integer) As Integer - To get the length of the device list. This seems to work as I get a CR_SUCCESS (I get a number around 8500. But as I'm not sure what is in the
1
4834
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' ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'GET_RIGHTS2' ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'GET_RIGHTS2' ORA-06550: line 1, column 7: PLS-00306: wrong number...
7
2691
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 name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
11
2725
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, adLockOptimistic If rsMain.RecordCount > 0 Then intID = Mid(rsMain(0), 3, 13) End If intCentreID = intBranchPrefix & (intID + 1)
0
9705
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
9576
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
10568
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
10323
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
10311
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
10074
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...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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();...
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.