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
Loading
aditya immadiPosted Sep 18, 2013, 8:17 AM
i got the solution
i call or store the id and name in sessions like
after that inserted values like this
cmd.CommandText = "insert into tb_userdata (employeeidfromtable1,Name,dicription,aboutme) values ('" + Session["id"].ToString() + "','" + Session["name"].ToString() + "','" + txtdesr.Text + "','" + txturl.Text + "');";
its woking fine
Thanks and Regards
aditya immadiPosted Sep 18, 2013, 7:43 AM
Thanks and Regards
Iftikar HussainPosted Sep 18, 2013, 7:42 AM
Regards,
Iftikar
Jignesh TrivediPosted Sep 18, 2013, 7:31 AM
from the error it looks, nameforlogin text box in not present on current page.
so check whether the text box is part of your current page or not...
aditya immadiPosted Sep 18, 2013, 7:22 AM
Actually i'm not getting id and name in name ,if i write like this for getting current name
Session["name"] = HttpContext.Current.User.Identity.Name;
it returns with my pc name like user-pc/1220
and if i write
Session["name"] = nameforlogin.Text;
in current page it throws eror like namefor login does not exist in curent content.
what can i do,
Thanks and Regards
Sanjeeb LenkaPosted Sep 18, 2013, 12:23 AM
Are you able to get the id and name in session. if yes try this query for insert
cmd.CommandText = "insert into tb_userdata (employeeidfromtable1,Name,dicription,aboutme) values ('" + Session["id"].ToString() + "','" + Session["name"].ToString() + "','" + txtdesr.Text + "','" + txturl.Text + "');";
Jignesh TrivediPosted Sep 17, 2013, 11:41 PM
define your variables(name and id) class level
public class a : System.Web.Page
{
string name;
string id;
}
now you may assign its value in page load event and other code is same.
hope this will help you.
Iftikar HussainPosted Sep 17, 2013, 11:38 PM
In your login page, after successful login you need to store the user id and name is session
protected void BtnLoginClick(object sender, EventArgs e)
{
Session["id"]=txtBxUserId.Text;
Session["name"]=txtBxUserName.Text;
}