我的思路:先從登陸頁面把用戶名傳過來,然後根據用戶名在表中查找,把該用戶的信息調出來顯示在頁面上
Label10.Text=Session["name"].ToString();
SqlConnection conn = sc.getSqlConnection();
conn.Open();
string sql1 = "select * from XX where Name=" + Session["name"] + "";
SqlCommand comm = new SqlCommand(sql1, conn);
DataSet ds = new DataSet();
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read())
{
this.Label11.Text = dr.GetString(dr.GetOrdinal("Nicename"));
this.Label12.Text = dr.GetString(dr.GetOrdinal("Sex"));
this.Label13.Text = dr.GetString(dr.GetOrdinal("PhoneNumber"));
this.Label14.Text = dr.GetString(dr.GetOrdinal("Email"));
}
dr.Close();
conn.Close();
請大神們幫忙看看錯在哪,或者思路不對 請大家告訴我該怎麼做。
謝謝了
string sql1 = "select * from XX where Name=" + Session["name"] + "";
字符串要引號
string sql1 = "select * from XX where Name='" + Session["name"] + "'";