Here in my SP for avoiding duplicate entry.
ALTER PROCEDURE [dbo].[tableuser]
@userName varchar(50)
AS
IF EXISTS (SELECT 'True' FROM tbl_user WHERE userName=@userName)
BEGIN
select 'Record already exists'
select @@identity;
END
BEGIN
select 'Record Added'
select @@identity;
END
SP for adding details of user:
ALTER PROCEDURE [dbo].[ADDuser]
-- Add the parameters for the stored procedure here
(
@userName varchar(50),
@password nvarchar(50),
@emailAddress nvarchar(50)
)
AS
BEGIN
INSERT INTO tbl_user(userName,password,emailAddress) values(@userName,@password,@emailAddress)
SELECT @@IDENTITY;
END
This is the C# code:
protected void save_Click(object sender, EventArgs e)
{
ClassBAL obj = new ClassBAL();
DataSet ds = new DataSet();
obj.userName = uname.Text;
obj.password = upass.Text;
obj.emailAddress = umail.Text;
List
foreach (ListItem value in CBL1.Items)
{
if (value.Selected)
{
preferences.Add(Convert.ToInt32(value.Value));
}
}
obj.preferences = preferences;
ds=obj.tableuser();
obj.ADDuser();
Response.Redirect("UserDisplay.aspx");
}
I have used DAL and BAL in my application. Everything goes well but duplicate entry occurs.
Pls help...
HanookPosted Nov 8, 2013, 7:50 AM
-- Add the parameters for the stored procedure here
(
@userName varchar(50),
@password nvarchar(50),
@emailAddress nvarchar(50)
)
AS
BEGIN
IF NOT EXISTS (SELECT 'True' FROM tbl_user WHERE userName=@userName)
BEGIN
INSERT INTO tbl_user(userName,password,emailAddress) values(@userName,@password,@emailAddress)
SELECT @@IDENTITY AS UserStatus;
END
ELSE
SELECT -1 AS UserStatus
END
Here -1 means user already exists; any positive value means user is newly added to database
HanookPosted Nov 14, 2013, 6:14 AM
then write click event for checking existance of UserID ( SELECT count(*) FROM TableName WHERE USerId = YourInput )
if exists display "Already exists"; else "username is available"
Saumya AgarwalPosted Nov 8, 2013, 8:00 AM
One more thing. The user here needs to enter all his details and then it directs to the GRIDVIEW page to show that the entered username is already in use. Is it possible that as soon he enters the username there is a message displaying that the username already exists? Either by using a button of CHECK AVAILABILITY or something like that?
Pls help
Saumya AgarwalPosted Nov 8, 2013, 7:46 AM
HanookPosted Nov 8, 2013, 7:44 AM
SP for adding details of user:
ALTER PROCEDURE [dbo].[ADDuser]
-- Add the parameters for the stored procedure here
(
@userName varchar(50),
@password nvarchar(50),
@emailAddress nvarchar(50)
)
AS
BEGIN
IF NOT EXISTS (SELECT 'True' FROM tbl_user WHERE userName=@userName)
BEGIN
INSERT INTO tbl_user(userName,password,emailAddress) values(@userName,@password,@emailAddress)
SELECT @@IDENTITY;
END