aditya immadi

aditya immadi

  • NA
  • 205
  • 69.4k

Retrieving id and Name for Already Login User using Sessions

Sep 17 2013 3:10 PM
Hai All,

I write this code for inserting user data if he is already existing user.but i need to get his name and current id using sessions ,after that i can send other details along with these two to my DB.how can i do this
 
on page load
// string name = Session["nameforlogin"].ToString();
// string id = Session["id"].ToString();
 
on button click
 
SqlConnection conn = new SqlConnection();
conn.ConnectionString="Data Source=USER-PC\\ADITYA;Initial Catalog=holder;Persist Security Info=True;User ID=sa;Password=123";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "insert into tb_userdata (employeeidfromtable1,Name,dicription,aboutme) values ('" +( Session["id"]) + "','" + Session["name"] + "','" +txtdesr.Text + "','"+txturl .Text+"');";
cmd.ExecuteNonQuery();
conn.Close();
thanks and regards  

Answers (8)