-3

here is my code... output is..

asd 24 23 System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:16:10 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:16:35 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:19:45 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:20:55 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:21:48 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:21:57 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:23:40 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:31:51 PM System.Web.UI.WebControls.Label System.Web.UI.WebControls.TextBox 08/14/2018 4:35:23 PM

Session["User_name"] = "lbl_User";
    Session["Product_Code"] = "txt_PrdCode";


    myConn.Open();
    SqlCommand cmd = new SqlCommand("insert into [Product_Detail] ([User_name],[Product_Code],[Log_Detail]) values ('" + lbl_User + "', '" + txt_PrdCode + "', '" + DateTime.Now.ToString() + "' ) ", myConn);
    cmd.ExecuteNonQuery();
    myConn.Close();
  • Possible duplicate of [Getting the .Text value from a TextBox](https://stackoverflow.com/questions/3334388/getting-the-text-value-from-a-textbox) – Drag and Drop Aug 14 '18 at 11:15
  • 2 main issue here. First a TextBox is a web control with a lot of properties. If you wan't to access the Text value of the TextBox you should use the Text property. – Drag and Drop Aug 14 '18 at 11:18
  • Then please stop hand crafting your sql query. Use either [parametrise query](https://stackoverflow.com/questions/35163361/how-can-i-add-user-supplied-input-to-an-sql-statement) or an orm. – Drag and Drop Aug 14 '18 at 11:19
  • What do you expect with this, line 1 : `Session["User_name"] = "lbl_User";` Because here your Session Username is "lbl_User" not the value of the label... – Drag and Drop Aug 14 '18 at 11:23
  • lbl_user stores User_Name and txt_PrdCode stores Product_Code – Kalpesh Patil Aug 14 '18 at 11:30
  • here i want to stored Logged user Details ie. his Name Which Product code he search and Exact time with date in database – Kalpesh Patil Aug 14 '18 at 11:30
  • 1
    Label have a `InnerText` property. And TextBox a `Text` property. It should be enought to get the information you need. – Drag and Drop Aug 14 '18 at 11:33

1 Answers1

-1

if you take the values from code behind you have to write thig like this

Session["User_name"] = lbl_User.Text;
Session["Product_Code"] = txt_PrdCode.Text; 

but first, you have to make this controls runat="server"

this will solve your problem