Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi Everybody,
I am attaching following code which is a fine project regarding conneting MS Access database, adding, deleting, inserting and updating records as well as good demonstartion of Image upload control.
Only problem I am facing with this code is that when I try to modify any record that can not be seen in Gridview.
Pl. find attached code file and test the site and Pl. help me to find error regarding UPDATE the record in database.
Thank you in anticipation
Swapnil JIrage

I think this site should provide facility to attach entire code file

C#
public partial class EditProfile : System.Web.UI.Page
{
    OleDbConnection con = new OleDbConnection();
     
    protected void Page_Load(object sender, EventArgs e)
    {
        ConnectionStringSettings datasettings = ConfigurationManager.ConnectionStrings["Databaseconnection"];
        string DbPath = "Provider=Microsoft.Jet.OLEDB.4.0; " + datasettings.ToString();
        con.ConnectionString = DbPath;
        con.Open();
        ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["Profiles"];
        string ProfilePath = settings.ToString();
        string FileName = "";
        if (FileUpload1.FileName == "")
            FileName = ProfilePath + "default.jpg";
        else
            FileName = ProfilePath + FileUpload1.FileName;
        string User_Edit = Convert.ToString(Session["User_Edit"]);
        string MyInsertCmd = "UPDATE users "+"SET User_Name='"+NameTextBox.Text+"',"+
           "[Password]='"+PasswordTextBox.Text+"',"+"First_Name='"+FirstNameTextBox.Text+"',"+
           "Last_Name='"+LastNameTextBox.Text+"',"+
           "Email='"+EmailTextBox.Text+"',"+"User_Group='"+UserDropDownList.Text+"',"+
           "Picture='"+FileName+"'"+"WHERE User_Name='"+User_Edit+"'";
        ExecuteCommand(MyInsertCmd);
        con.Close();
    }
    public void ExecuteCommand(string MyCmd)
    {
        try
        {
            OleDbCommand command = new OleDbCommand();
            command.Connection = con;
            command.CommandText = MyCmd;
            command.CommandType = CommandType.Text;
            command.ExecuteNonQuery();
            if (FileUpload1.PostedFile != null)
                SaveProfileImage();
            if (NameTextBox.BackColor == Color.Red)
                NameTextBox.BackColor = Color.White;
        }
        catch (OleDbException)
        {
            NameTextBox.BackColor = Color.Red;
        }
        catch (Exception ex)
        {
            Response.Write("Some error are occured, here are the details");
            Response.Write(ex.ToString());
        }
    }
    public void SaveProfileImage()
    {
        HttpPostedFile MyFileRef = FileUpload1.PostedFile;
        int MyFileSize = MyFileRef.ContentLength;
        byte[] MyFileBuffer = new byte[MyFileSize];
        MyFileRef.InputStream.Read(MyFileBuffer, 0, MyFileSize);
        ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["Profiles"];
        string ProfilePath = settings.ToString() + NameTextBox.Text + ".jpg";
        FileStream newFile = new FileStream(ProfilePath, FileMode.Create);
        newFile.Write(MyFileBuffer, 0, MyFileBuffer.Length);
        newFile.Close();
    }
    protected void GoButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("DisplayProfile.aspx");
    }
}
Posted
Updated 8-Mar-13 11:24am
v2
Comments
R. Giskard Reventlov 8-Mar-13 17:58pm    
What is the error???

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