473,396 Members | 1,693 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.

ASP, SQL Insert Problem

Hi,

I'm facing typical problem in SQL Server SP & ASP
When ever i try to insert new record, the record has been inserted and gives
error " User Already Found"
How to solve this issue?

Thanks in Advance.
-DNK
My SP:

-------------------------
CREATE PROCEDURE [dbo].[sp_InsertUser]
( @puserid varchar(50) , @pfname varchar(255), @plname varchar(255),
@pudept varchar(100), @urights varchar(100), @upassw varbinary(50),
@status varchar(50) )
as
if exists(select userid from SALES_USERS where USERID = @puserid)
return 55555
else
insert into SALES_USERS
(USERID,FIRSTNAME,LASTNAME,DEPARTMENT,RIGHTS,UPASS WORD,STATUS)
values (@puserid,@pfname,@plname,@pudept,@urights,@upassw ,@status)
return @@error
GO
-------------------------
My ASP:

---------------------------
set connect = server.createobject("adodb.connection")
set cmd = server.createobject("adodb.command")
connect.open SQLConString
set cmd.activeconnection = connect
cmd.commandtype = 4 'sp
cmd.commandtext = "sp_InsertUser"
cmd.parameters(1) = uid
cmd.parameters(2) = ufn
cmd.parameters(3) = uln
cmd.parameters(4) = udt
cmd.parameters(5) = urt
cmd.parameters(6) = upa
cmd.parameters(7) = "Active"
cmd.execute
returnvalue = cmd.Parameters(1)
Set cmd = Nothing
Set connect = Nothing
if returnvalue=0 then
Response.write "User Added"
else
Response.write "User Already Found"
end if
--------------------------------
Sep 5 '05 #1
1 1759
DNKMCA wrote:
Hi,

I'm facing typical problem in SQL Server SP & ASP
When ever i try to insert new record, the record has been inserted
and gives error " User Already Found"
How to solve this issue?

Thanks in Advance.
-DNK
My SP:

-------------------------
CREATE PROCEDURE [dbo].[sp_InsertUser]
It is a bad idea to use "sp_" to prefix user stored procedures. SQL Server
assumes that any procedure using that prefix is a system procedure and
accordingly looks in the Master database to see if it exests there, causing
a slight performance penalty. Additionally, if you happen to give one of
your procesures the same name as an existing procedure, you will have a hard
time figuring out why your procedure never gets executed ...
( @puserid varchar(50) , @pfname varchar(255), @plname varchar(255),
@pudept varchar(100), @urights varchar(100), @upassw varbinary(50),
@status varchar(50) )
No output parameters ....
as
The lack of a "SET NOCOUNT ON" statement here may prevent you from being
able to retrieve your returned value. You should make it a practice to begin
your procedures with that statement.
if exists(select userid from SALES_USERS where USERID = @puserid)
return 55555
else
insert into SALES_USERS
(USERID,FIRSTNAME,LASTNAME,DEPARTMENT,RIGHTS,UPASS WORD,STATUS)
values (@puserid,@pfname,@plname,@pudept,@urights,@upassw ,@status)
return @@error
GO
OK, so you want to use the Return parameter to return the result ...

Do you know the difference between return and output parameters? If not,
read this:
http://groups-beta.google.com/group/...935bd7c531d82b
-------------------------
My ASP:

---------------------------
set connect = server.createobject("adodb.connection")
set cmd = server.createobject("adodb.command")
connect.open SQLConString
set cmd.activeconnection = connect
cmd.commandtype = 4 'sp
cmd.commandtext = "sp_InsertUser"
cmd.parameters(1) = uid
cmd.parameters(2) = ufn
cmd.parameters(3) = uln
cmd.parameters(4) = udt
cmd.parameters(5) = urt
cmd.parameters(6) = upa
cmd.parameters(7) = "Active"
cmd.execute
You should prevent ADO from creating a recordset by telling it that you are
not expecting records to be returned from your procedure by using 128
(adExecuteNoRecords) as the <options> argument in the call to the Execute
method:

cmd.execute ,,128
returnvalue = cmd.Parameters(1)
This parameter is an input parameter. It will not contain the value returned
by your RETURN statements. The first parameter, cmd.Parameters(0), will
contain the return value if you configure it correctly. You might wish to
try my Command object code generator available here:
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear
Set cmd = Nothing
Set connect = Nothing
if returnvalue=0 then
Response.write "User Added"
else
Response.write "User Already Found"


There could be another reason for your procedure to fail besides a duplicate
key violation. Even though your user will probably not need to see the
actual value returned from your procedure, you might want to consider
logging the non-zero value as a troubleshooting aid.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Sep 5 '05 #2

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

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
0
by: jtocci | last post by:
I'm having a big problem with CREATE RULE...ON INSERT...INSERT INTO...SELECT...FROM...WHERE when I want to INSERT several (20~50) records based on a single INSERT to a view. Either I get a 'too...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
2
by: alexmaster_2004 | last post by:
hi i have made an application using C# that access sql2000. this application is just used to insert data to the database. i use something like this in my code: // string colmnA = TextBox1.Text;...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
6
by: sgulciny | last post by:
hi friends; I have problem about sql server insert and update in client side. I am coding windows application with c#.When I run my code in database server computer all is fine.I can see data,...
8
by: Red | last post by:
If auto-format is turned off in VS2008, there is apparently no way to indent a line. Under Tools->Options->Text Editor->C#->Formatting, there are three checkboxes. Unchecking those seems to cause...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.