Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's dirty, and wrong, but this would work in a pinch I guess. </p> <pre><code> protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { var sql = @"SELECT * from Users where userName = ?user and password = ?pass"; DataSet ds = new DataSet(); MySqlCommand commandWithParams = new MySqlCommand(sql); commandWithParams.Parameters.AddWithValue("?user", Login1.UserName); commandWithParams.Parameters.AddWithValue("?pass", Login1.Password); MySqlConnection conn = new MySqlConnection("myconn string"); if (conn.State != ConnectionState.Open) conn.Open(); commandWithParams.Connection = conn; MySqlDataAdapter da = new MySqlDataAdapter(commandWithParams); da.Fill(ds); DataTable dt = ds.Tables[0]; DataRow dr = dt.Rows[0]; conn.Close(); conn.Dispose(); da.Dispose(); if (dt.Rows.Count != 0)//I'm sure this has a better way { Session["userId"] = Convert.ToString(dr["userId"]); Session["userName"] = Convert.ToString(dr["userName"]); e.Authenticated = true; Reponse.Redirect("your_page.aspx"); } else { e.Authenticated = false; } } </code></pre> <p>Here it is again using the Reader method and Odbc.</p> <pre><code> OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=x; Password=x; OPTION=3;"); cn.Open(); OdbcCommand cmd = new OdbcCommand("Select * from users where username=? and password=?", cn); cmd.Parameters.Add("@username", OdbcType.VarChar); cmd.Parameters["@username"].Value = "test"; cmd.Parameters.Add("@password", OdbcType.VarChar); cmd.Parameters["@password"].Value = "test1"; OdbcDataReader dr = default(OdbcDataReader); dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); string theUser = (string)dr["userName"]; string theUserId = Convert.ToString(dr["userId"]); } </code></pre> <p>The you can set <code>theUser</code> and <code>theUserId</code> into session like so:</p> <pre><code>Session.Add("userName", theUser); Session.Add("userId", theUserId); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload