Как получить имя пользователя при входе в систему и сохранить его в базе данных, когда пользователи нажмут кнопку голосования
When the users click the vote button, the candidateID that being displayed in the gridview will be store to the database.However, I want to store who vote for the particular candidate (store they studentID). I'd like capture thier username when they login, and when they click the vote button, insert their studentID to the database
I store the session in the user login page. How can I store it to the database using the insert command(when they click the vote button)?
Что я уже пробовал:
<pre><pre lang="c#"> protected void LinkButton_Click(Object sender, EventArgs e) { String MyConnection2 = "Server=localhost;database=ovs;Uid=root;password=; Convert Zero Datetime=True"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer; Label lblStudentId = (Label)grdrow.Cells[0].FindControl("lblID"); string studentId = lblStudentId.Text; String query = "insert into voting (studentID,)values ('" + lblStudentId.Text + "')"; MySqlCommand MyCommand2 = new MySqlCommand(query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { } MyConn2.Close(); } }
<pre lang="c#"> Session["UserName"] = txtID.Text; txtID.Text = Session["UserName"].ToString();
BillWoodruff
Вот вам и анонимное голосование.