473,473 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Method Execute of Object - Command Falied(Runtime error-2147217900)

I am getting above error,

could pls anyone help me........?

Soruce Code :

Sub updateOfferCategoryAmounts(ByVal Transid As Long)
Dim spComm As Command
Set spComm = New Command
Dim intCatID As Integer
Dim rsBarADO As Recordset
Dim spADO As Command

Set spADO = New Command
spADO.CommandText = "sp_get_TransactionCategories"
spADO.CommandType = adCmdStoredProc
spADO.ActiveConnection = cnADO

Set rsBarADO = New Recordset
rsBarADO.CacheSize = 50

spADO.Parameters.Append spADO.CreateParameter("@TransID",
adBigInt, adParamInput, 20, Transid)
rsBarADO.Open spADO, , adOpenStatic, adLockReadOnly

While Not rsBarADO.EOF
Dim rowsAffected As Long
intCatID = rsBarADO("categoryID")

spComm.CommandText = "sp_insert_CatAmount"
spComm.CommandType = adCmdStoredProc
spComm.ActiveConnection = cnADO

spComm.Parameters.Append spComm.CreateParameter("@TransID",
adBigInt, adParamInput, 20, Transid)
spComm.Parameters.Append spComm.CreateParameter("@CatID",
adInteger, adParamInput, 4, intCatID)
spComm.Execute

rsBarADO.MoveNext

Wend

Set rsBarADO = Nothing
Set spADO = Nothing

End Sub

Stored Procedure :
CREATE proc sp_insert_CatAmount @TransID bigint, @CatID int
as

declare @Amount money
select @Amount = SUM(DiscountValue)
from
dbo.fn_list_PossibleOffersCategory(@TransId, @CatID)
if @Amount = null

set @Amount = 0

insert into
Current_SalesRefund_Discount (
TransactionNo,
CategoryID,
Discount)
values (
@TransID,
@CatID, @Amount )

GO
Jul 20 '05 #1
1 4252
[posted and mailed, please reply in news]

Nachi (na********@yahoo.com) writes:
I am getting above error,

could pls anyone help me........?
First, before you actually fix the error - keep it! What you need is
to improve your error handling, so that you can get useful diagnosis
from SQL Server. You need to have an On Error Goto, and in that part
you pick what is in the .Errors collection on the connection object,
and then print this out. (One message is also in the plain Err.Description.)

In this case you probaly would have gotten the error "Cannot insert the
value NULL into column 'Discount', table 'Current_SalesRefund_Discount';
column does not allow nulls. INSERT fails."

Why? Hang on. But first another issue:
CREATE proc sp_insert_CatAmount @TransID bigint, @CatID int
Don't use the sp_ prefix for stored procedure. This prefix is reserved
for system procedures, and SQL Server first looks for these in the master
database.
if @Amount = null

set @Amount = 0
But this will not have any effect, because @Amout is never equal to NULL,
because nothing is ever equal to NULL. NULL is an unknown value, so you
can't tell whether two NULLs are the same unknown value or not.

When testing for NULL, you should use IS NULL or IS NOT NULL instead.

In this particular case, it would have been more convenient to write:
insert into
Current_SalesRefund_Discount (
TransactionNo,
CategoryID,
Discount)
values (
@TransID,
@CatID, coalesce(@Amount, 0) )


coalesce is a function that accepts a list of values and returns the
first non-NULL value in the list.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

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

Similar topics

1
by: Perseus | last post by:
Hi all , I would like to know how could I execute a command/script on server side which is located in the same directory as the asp ? And how could I response.write() the result? Thanks. ...
2
by: Norman Fritag | last post by:
Hi there The below code executes some queries. As newbie I was wondering weather you are better of using connection execute or command execute to execute queries? I am asking as...
1
by: tc | last post by:
Hi, all I would like to ask how can I execute a command(e.g. dir/w) by using C#? Thanks
6
by: Lucas Cowald | last post by:
Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2 -p Can you show me a code how to run this...
7
by: Risen | last post by:
Hi,all, I want to execute SQL command " DROP DATABASE mydb" and "Restore DATABASE ....." in vb.net 2003. But it always shows error. If any body can tell me how to execute sql command as above?...
1
by: peres232323 | last post by:
Hi, I'm working on Windows XP. I need to execute a command (e.g. MyCommand arg1 arg2 arg3) how can i execute it from a php file?
4
by: jram01 | last post by:
Hi Folks, I am facing problem to to execute .sql command in sql prompt using perl script. I am able to connect sql promt using " my $odbcinput = "odbcinput.txt"; my...
8
by: mahmoodtyagi | last post by:
Just I want to execute a command through PHP program. Thanx & Regards Mahmood Ali
16
rahuljaiswal1987
by: rahuljaiswal1987 | last post by:
Videoagent.exe -s 100.100.10.1 -c 3 -d 08252002 -b 14:12:35 -e 14:15:12 -u USERID -p PASSWORD This is a command to execute video agent with these parameter. I want to execute this command...
1
by: syminder | last post by:
Hi guy, I using the batch program to trigger specific main class in JAR. It is simplest JAVA -cp %classpath% Main_class cmd instruction. Initialy the jdk is not installing cause JAVA command...
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
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.