using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
using System.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Focus();
}
private void InitializeComponent()
{
this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
protected void cmdSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
else
{
//lblMessage.Text = "Invalid Login, please try again!";
}
}
}
private bool DBConnection(string txtUser, string txtPass)
{
// SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
String ConnectionString = "server=iconn;database=db_test;user id=sa;password=iconn;";
SqlConnection Conn = new SqlConnection(ConnectionString);
SqlCommand myCmd = new SqlCommand("sp_ValidateUser", Conn);
myCmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
//SqlParameter returnParam;
objParam1 = myCmd.Parameters.Add("@txtUserName", SqlDbType.VarChar);
objParam2 = myCmd.Parameters.Add("@txtPassword", SqlDbType.VarChar);
//objreturnParam = myCmd.Parameters.Add ("@Num_of_User", SqlDbType.Int);
objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
//objreturnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = txtUser;
objParam2.Value = txtPass;
try
{
if (Conn.State == ConnectionState.Closed)
{
Conn.Open();
}
SqlDataReader objReader;
objReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection);
while (objReader.Read())
{
if ((bool)(objReader.GetValue(0)) == false)
{
lblMessage.Text = "Invalid Login!";
//return false;
}
else
{
objReader.Close();
return true;
}
}
}
catch
{
lblMessage.Text = "Error Connecting to the database!";
return false;
}
}
}
Error 1 '_Default.DBConnection(string, string)': not all code paths return a value C:\Documents and Settings\Administrator.ITECH\My Documents\Visual Studio 2008\WebSites\web_login\login.aspx.cs 46 18 C:\...\web_login\
hii.thnkss for excellent login tutorial.it's my first post to this forum
the procedure posted by u in this forum is executing succesful.i am using sql server.plzz help