0% found this document useful (0 votes)
22 views

Dot Net

This document contains code for a login page that uses a SQL connection string stored in the Web.config file to connect to a database and execute a stored procedure called "SP_Login" to authenticate user credentials. If the stored procedure returns rows, the user is redirected to the Default2 page upon a successful login.

Uploaded by

kamalmaru
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Dot Net

This document contains code for a login page that uses a SQL connection string stored in the Web.config file to connect to a database and execute a stored procedure called "SP_Login" to authenticate user credentials. If the stored procedure returns rows, the user is redirected to the Default2 page upon a successful login.

Uploaded by

kamalmaru
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Web.

config

<configuration>
<appSettings/>
<connectionStrings>
<add name="DBConfig" connectionString="User ID=sa;Initial
Catalog=PTest;Data Source=KAMALM"/>
</connectionStrings>
<system.web>

Login page

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page


{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
con = new
SqlConnection(ConfigurationManager.ConnectionStrings["DBConfig"].ToString());
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
con.Open();

cmd = new SqlCommand();


cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_Login";
cmd.Parameters.Add("@uid", SqlDbType.VarChar, 30).Value = txtUid.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 20).Value =
txtPassword.Text;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Server.Transfer("Default2.aspx");
}
}
}

You might also like