PDA

View Full Version : مبتدی: فراخوانی اطلاعات کاربر با استفاده از session["user_id"] از پایگاه داده



voice.of.silence
شنبه 25 شهریور 1396, 18:56 عصر
سلام دوستان:
من می خوام که profile کاربر رو زمان log in در صفحه ی profile از پایگاه داده نمایش دهم.
اما با خطا رو به رو می شم .



SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=my_web_db;Integrated Security=True");
con.Open();


SqlCommand cmd = new SqlCommand("select * from tbl_user where id=@id", con);
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(Session["user_id"]));


SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();

if(dt.Rows.Count>0)
{
txtfn.Text = dt.Rows[0][1].ToString();


}
else
{
Response.Write("The requested user profile not found.");


}

خواشحال می شم اگه منو راهنمایی کنید.
با سپاس فراوان.