public class UserDA { private static string _connStr = ConfigurationManager.ConnectionStrings["airmazin"].ConnectionString;
//update,delete,insert,getuser
public static void UserInsert(User user)
{
string queryStr = "INSERT INTO Account (username, gender, email, password) values (@username, @gender, @email, @password);";
SqlConnection conn = new SqlConnection(_connStr);
SqlCommand cmd = new SqlCommand(queryStr, conn);
cmd.Parameters.AddWithValue("@username", user.userName);
cmd.Parameters.AddWithValue("@gender", user.gender);
cmd.Parameters.AddWithValue("@email", user.email);
cmd.Parameters.AddWithValue("@password", user.password);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
protected void btn_Submit_Click(object sender, EventArgs e) {
string userName = tb_userName.Text;
string gender = rbl_gender.SelectedValue.ToString();
string email = tb_email.Text;
string password = tb_password.Text;
User user = new User(userName, gender, email, password);
UserDA.UserInsert(user);
}
protected void Page_Load(object sender, EventArgs e) {
}
protected void btn_Login_Click(object sender, EventArgs e)
{
//if (txt_userEmail == null) { }
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["airmazin"].ToString());
con.Open();
string query = "select count from Account where email='" + txt_userEmail.Text+ "' and password='" + txt_userPass.Text +"'" ;
SqlCommand cmd = new SqlCommand(query, con);
string output = cmd.ExecuteScalar().ToString();
con.Close();
if (output == "1")
{
// Create a session
Session["Account"] = txt_userEmail.Text;
Response.Redirect("User_Profile.aspx");
}
else
{
Response.Write("<script>alert('Login NOT successful');</script>");
}
}
protected void btn_loginSignup_Click(object sender, EventArgs e)
{
Response.Redirect("SignUp.aspx");
}
}
I have inserted data into the data base and how do I store it into a session and display the current users information(Eg: Username, email, gender etc) on my profile page.
select count
because it will give you the number of records. Get the actual info you need and then store it in the session. – CodingYoshiselect count *
using management studio or another tool and see what you get.select count *
will not work because it Has syntax error.select count(*)
will work but that will return a number. You need to get username, email, name etc (whatever you need) so useselect username, email...
– CodingYoshi