Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2007, 01:31 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code running without any result

Hi,
I am running Access form to pass parameters to a stored procedure in sql server backend in the pubs database to update records. However, the code is working but the results are not. This means for some reason the code is not updating the data. I believe, it has to do with data type issues. I am not certain though. I would appreciate if someone can help me to figure out why the stored procedure is not running. Thanks
CODE:
Private Sub cmdRunProc1_Click()

Dim conn As ADODB.Connection
'Dim cmdUpdate As ADODB.Command
Dim lngRecs
Dim strType
Dim curPercent


Set conn = New ADODB.Connection


conn.Provider = "SQLOLEDB"


conn.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog=pubs;Data Source=USILDEK1-21001;User ID=sa;Password=alloyd;"
conn.Open

Set cmdUpdate = New ADODB.Command
cmdUpdate.CommandType = adCmdStoredProc
cmdUpdate.CommandText = "usp_UpdatePrices"
Set cmdUpdate.ActiveConnection = conn




' Get the form values
strType = Forms!frmParamPassing_mod!txtBookType
curPercent = Forms!frmParamPassing_mod!txtPercent
curPercent1 = CCur(Forms!frmParamPassing_mod!txtPercent)


    ' Add the parameters
    cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@Type", adVarWChar, adParamInput, 12, strType)
    cmdUpdate.Parameters.Append cmdUpdate.CreateParameter("@Percent", adCurrency, adParamInput, , curPercent1)

' Execute the command
    cmdUpdate.Execute lngRecs, , adExecuteNoRecords



' And finally tell the user what's happened

MsgBox ("Procedure complete. Records were updated")

Set conn = Nothing
Set cmdUpdate = Nothing
End Sub


STORED PROCEDURE CODE:

create procedure usp_updateprices

@type char(12),
@percent money
as
update titles
set price = price * ( 1 + @percent /100)
where type = @type
 
Old July 11th, 2007, 02:29 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi jack123,

It could indeed be a data type issue. Your procedure expects a char(12). The char data type is padded with spaces by default. If the underlying value you're querying is of a different type, you may have a mismatch. That is, "SomeValue " is not the same as "SomeValue".

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 11th, 2007, 05:02 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Folks
This work now. I do not know why it was not working before. Anyway,
Thanks for viewing.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Running the source code Sheraz Khan ASP.NET 2.0 Professional 1 September 11th, 2007 01:47 AM
Please help my code is not giving me a result set yudee JSP Basics 0 September 20th, 2006 09:55 AM
Code not running larryg BOOK: Beginning Access VBA 3 August 18th, 2006 08:36 AM
Send code to server and getto=ing back result topshed Classic ASP Professional 1 January 30th, 2006 12:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.