i Ergebnis in einer Sitzung zuordnen wollenAssign Abfrageergebnis in einer Sitzung
C# -Code
protected void BindData()
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-677TN4G\SQLEXPRESS;Initial Catalog=homework;Persist Security Info=True;User ID=sa;Password=123456");
DataSet ds = new DataSet();
DataTable FromTable = new DataTable();
con.Open();
string cmdstr = "Select CourseName from Staff where [email protected]";
SqlCommand cmd = new SqlCommand(cmdstr, con);
cmd.Parameters.AddWithValue("@idd", Session["id"].ToString());
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
}
so, wie ich es tun kann ich versuche
Session["id"] = cmdstr.Text;
zu tun, aber es funktioniert nicht
ich mache es so, aber nicht arbeiten
Ich mache es wie dieses
protected void BindData()
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-677TN4G\SQLEXPRESS;Initial Catalog=homework;Persist Security Info=True;User ID=sa;Password=123456");
DataSet ds = new DataSet();
DataTable FromTable = new DataTable();
con.Open();
string cmdstr = "Select CourseName from Staff where [email protected]";
SqlCommand cmd = new SqlCommand(cmdstr, con);
cmd.Parameters.AddWithValue("@idd", Session["id"].ToString());
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
DataList1.DataSource = ds.Tables[0];
Session.Add("Staff", ds.Tables[0]);
DataList1.DataBind();
Label1.Visible = true;
Label1.Text = "Course Name is : " + Session["Staff"].ToString();
}
und der Ausgang ist
Kursname ist: Tabelle
nicht der ausgewählte Wert
Könnten Sie bitte weitere Informationen über Ihre Anforderungen hinzufügen, '' cmdstr ist ein String-Variable es keine Eigenschaft enthält genannt 'Text' –
Wie ich sehe,' cmdstr' ist eine Zeichenfolge, kein Textfeld-Steuerelement . Woher kommt Ihr 'Session [" id "] - Wert? –
Ich möchte die Sitzung kommt aus dem Ergebnis der Tabelle und zeigen Sie es in Label – Sulaiman