the following is the complete solution u r looking for,
the stored procedure:
use [YOURDB]
go
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'sp_Login')
BEGIN
DROP Procedure [dbo].[sp_Login]
END
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/*
File Name : sp_Login.sql
Description :
Author : Vinay.T
Date :
*/
CREATE Procedure [dbo].[sp_Login]
(
@Username VarChar(50)
,@UPassword varChar(50)
,@OutRes int output
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrMsg NVARCHAR(510) --
,@ErrorSeverity INT --16 if business error
BEGIN
SET @OutRes = (SELECT count(*) FROM Log_Users WHERE Username = @Username And [Password] = @UPassword)
END
GOTO SUCCESS
SUCCESS:
RETURN 1
CRASH:
RAISERROR (@ErrMsg, @ErrorSeverity, 1) WITH NOWAIT
END
GO
GRANT EXEC ON [dbo].[sp_Login] TO PUBLIC
GO
2:the button click event code:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("sp_Login", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", txtUserName.Text);
cmd.Parameters.AddWithValue("@UPassword", txtPWD.Text);
cmd.Parameters.Add("@OutRes", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
int output = (int)cmd.Parameters["@OutRes"].Value;
if (output == 1)
{
Response.Redirect("Details.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username Or Password')</script>");
}
let me know this works on not.. ? run the sp against your database..