<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Security;
using System.Data;
namespace testing{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string username = TextBox1.Text;
string password = TextBox2.Text;
SqlConnection connection = null;
SqlCommand command = null;
SqlDataReader dataReader = null;
try
{
string connectionString = ConfigurationManager.ConnectionStrings["testing ConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
connection.Open();
string sql = "SELECT * from Staff where username='" + username + "'And Password='" + password + "'";
command = new SqlCommand(sql, connection);
command.Parameters.Add("@username", SqlDbType.VarChar, 15).Value = username;
command.Parameters.Add("@password", SqlDbType.VarChar, 30).Value = password;
dataReader = command.ExecuteReader();
if (dataReader.Read())
{
Session.Add("username", username);
}
else
{
System.Diagnostics.EventLog.WriteEntry(
"Membership Registration"
, string.Format("Invalid login attempt for user {0}", username)
, System.Diagnostics.EventLogEntryType.FailureAudit);
Response.Write("Invalid username");
}
dataReader.Close();
connection.Close();
}
catch(Exception ex)
{
System.Diagnostics.EventLog.WriteEntry (
"Membership Registration"
, string.Format("Unexpected error: {0}", ex.Message)
,System.Diagnostics.EventLogEntryType.Error);
Response.Write ("Unexpected error");
}
}
}
protected void Button2_Click(object sender, EventArgs e) {
Response.Redirect("Membership Registration.aspx");
}
}
I also having this error at void Button2_Click. Can someone tell me my error?