我正在尝试进行如此多的会话,以检索在我的网站内为其创建会话的个人的信息。现在,执行标量只为我分配给此处创建的不同会话的所有标签提供了一个值。我很天真并试图学习这一点,但我不太理解执行阅读器命令......所以请尽可能编写代码......
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("Select * from Student where StudId=@sid and Password=@pw", con);
cmd.Parameters.AddWithValue("@sid", TextBox1.Text);
cmd.Parameters.AddWithValue("@pw", TextBox2.Text);
con.Open();
string name = Convert.ToString(cmd.ExecuteScalar());
string lastname = Convert.ToString(cmd.ExecuteScalar());
string gender = Convert.ToString(cmd.ExecuteScalar());
string dob = Convert.ToString(cmd.ExecuteScalar());
string pno = Convert.ToString(cmd.ExecuteScalar());
string address = Convert.ToString(cmd.ExecuteScalar());
string branch = Convert.ToString(cmd.ExecuteScalar());
string library = Convert.ToString(cmd.ExecuteScalar());
string bus = Convert.ToString(cmd.ExecuteScalar());
string hostel = Convert.ToString(cmd.ExecuteScalar());
string semester = Convert.ToString(cmd.ExecuteScalar());
string fname = Convert.ToString(cmd.ExecuteScalar());
string mname = Convert.ToString(cmd.ExecuteScalar());
string fpno = Convert.ToString(cmd.ExecuteScalar());
string mpno = Convert.ToString(cmd.ExecuteScalar());
string email = Convert.ToString(cmd.ExecuteScalar());
string img = Convert.ToString(cmd.ExecuteScalar());
con.Close();
Session.Add("StudId", TextBox1.Text);
Session.Add("StudFirstName", name);
Session.Add("StudLastName", lastname);
Session.Add("Gender", gender);
Session.Add("DateOfBirth", dob);
Session.Add("PhoneNo", pno);
Session.Add("Address", address);
Session.Add("BranchId", branch);
Session.Add("Library", library);
Session.Add("Bus", bus);
Session.Add("Hostel", hostel);
Session.Add("SemesterId", semester);
Session.Add("FatherName", fname);
Session.Add("MotherName", mname);
Session.Add("FatherPhoneNo", fpno);
Session.Add("MotherPhoneNo", mpno);
Session.Add("EmailID", email);
Session.Add("StudImg", img);
FormsAuthentication.RedirectFromLoginPage(name, false);