hi,
try my codes without output parameter..
sql section:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[insertUser] (
@UserName varchar(50),
@Password varchar(50),
@FirstName varchar(50),
@LastName varchar(50),
@Email varchar(150),
@Mobile varchar(50)
AS
BEGIN
Declare @UserCount int;
Declare @result int);
set @UserCount = SELECT COUNT(*) FROM users WHERE UserName = @UserName;
IF(@UserCount > 0)
begin
Set @Result = -1
return
end
ELSE
begin
INSERT INTO users(UserName,Password,FirstName,LastName,Email,MobileNo)VALUES (@UserName,@Password,@FirstName,@LastName,@Email,@Mobile);
Set @Result = -2;
return
end
END
Business layer:
public int insertUser(registerUser reg)
{
dbcon obj = new dbcon();
SqlParameter[] objParams = new SqlParameter[6];
objParams[0] = new SqlParameter("@UserName", reg.UserName);
objParams[1] = new SqlParameter("@Password", reg.Password);
objParams[2] = new SqlParameter("@FirstName", reg.FirstName);
objParams[3] = new SqlParameter("@LastName", reg.LastName);
objParams[4] = new SqlParameter("@Email", reg.Email);
objParams[5] = new SqlParameter("@Mobile", reg.MobileNo);
int b=obj.ExecuteScalar("insertUser", objParams);
return b;
}
presentation layer:
registerUser reg = new registerUser();
reg.UserName = txtUserName.Text;
reg.Password = txtPassword.Text;
reg.FirstName = txtfirstname.Text;
reg.LastName = txtlastname.Text;
reg.Email = txtemail.Text;
reg.MobileNo = txtmobileno.Text;
int b =reg.insertUser(reg);
if (b == -2)
{
lblreg.Text =
}
else
{
lblreg.Text =
}
try this codes and ask me if it gives you error.
hope it helps..
mark this as answer if it helps you..
thanks