Actually i have a small problem in this code in my login page i mention dropdownlistbox in that one we have "admin" and "user" if i click on admin it is going to admintable and checking wheather username and password right or wrong it is working.
2.I have adduserpage when i enter ther username,password,conform password it saving in ssss table it is also working now in dropdownlist if i click user it have to go that ssss table and retrive that data .
Login.cs Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
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 billing1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
String qry="select * from adminlogin where username=@username and password=@password";
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|Datadirectory|\billing.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(qry,con);
SqlDataReader rdr;
cmd.Parameters.AddWithValue("@username", textbox3.Text);
cmd.Parameters.AddWithValue("@password", textbox4.Text);
con.Open();
rdr = cmd.ExecuteReader();
if (!rdr.HasRows)
{
con.Close();
Label2.Visible = true;
return;
}
rdr.Read();
Session["Loginid"] = rdr[0].ToString();
con.Close();
Response.Redirect("~\\billing2.aspx");
}
}
Adduser.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class billing2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|Datadirectory|\billing.mdf;Integrated Security=True;User Instance=True");
string str = "select count(*) from ssss where uname=@uname";
con.Open();
SqlCommand cmd = new SqlCommand(str, con);
cmd.Parameters.AddWithValue("@username", textusername.Text);
Label1.Visible = true;
if (Convert.ToInt32(cmd.ExecuteScalar()) == 0)
{
string qry = "insert into ssss values(@uname,@pwd,@cnpwd)";
SqlCommand cmd2 = new SqlCommand(qry, con);
cmd2.Parameters.AddWithValue("@uname", textusername.Text);
cmd2.Parameters.AddWithValue("@pwd", textpassword.Text);
cmd2.Parameters.AddWithValue("@cnpwd", TextBox1.Text);
cmd2.ExecuteNonQuery();
Response.Redirect("~\\billing6.aspx");
}
con.Close();
}
}