Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using MySql.Data.MySqlClient;


public partial class profile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = Session["user"].ToString();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        MySqlConnection con = new MySqlConnection();
        string str = ConfigurationManager.ConnectionStrings["netConnectionString"].ConnectionString;
        con.ConnectionString = str;
        con.Open();

        if (con.State.ToString() == "Open")
        {
            MySqlCommand cmd = new MySqlCommand("update users Set education=@c,about=@d,interest=@e where user_name="Session["user"].ToString"",con);
            cmd.Parameters.AddWithValue("@c", TextBox1.Text);
            cmd.Parameters.AddWithValue("@d", TextBox2.Text);
            cmd.Parameters.AddWithValue("@e", TextBox3.Text);
            cmd.ExecuteNonQuery();
            Label5.Text = "Well done profile updated!!";
        }
    }
}


I want to update user information from its profile i am getting error at this (where user_name="Session["user"].ToString") see above code please help me
Posted
Updated 14-Aug-14 21:08pm
v2
Comments
Kim Togo 15-Aug-14 3:09am    
Are you getting a compiler error or a runtime error ? - Like an excpetion.
ben.josey 15-Aug-14 3:11am    
its showing error at ---where user_name="Session["user"].ToString""

Rewrite your new MySqlCommand to this:
C#
MySqlCommand cmd = new MySqlCommand("UPDATE users SET education=@c,about=@d,interest=@e WHERE user_name=@userName", con);
            cmd.Parameters.AddWithValue("@c", TextBox1.Text);
            cmd.Parameters.AddWithValue("@d", TextBox2.Text);
            cmd.Parameters.AddWithValue("@e", TextBox3.Text);
            cmd.Parameters.AddWithValue("@userName", Session["user"].ToString());
            cmd.ExecuteNonQuery();
            Label5.Text = "Well done profile updated!!";
 
Share this answer
 
You should not give the session value like that. Use it this way:

user_name='"+Session.Contents["user"]+"'


in the sql query.
Happy Coding :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900