1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

I got a problem when updating a table in MS Access

Discussion in 'ASP' started by Zazabazulla, Aug 19, 2008.

  1. Zazabazulla

    Zazabazulla New Member

    Hi to all,

    I got a problem whereby do not know how to update a particular row. There is a table containing a list of jobs being indexed by JobID, listed in a gridview. whenever i choose to approve a specific job, the status of Phase changes from blank to 'Approved'. should i remove the WHERE statement, the code will change every row in the whole gridview - so may i believe i got something wrong in the SQL statement.
    the code is:

    Code:
    protected void btnApprove_Click(object sender, EventArgs e)
        {
    
            //Int32 index = Int32.Parse(lblIndex.Text.Trim());
            string index = lblIndex.Text;
            string ConnString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|intranet_db.mdb";
            string SqlString = "Update tblJob Set Phase = 'Approval' WHERE JobID='"+ index +"';";
            
            try
            {
                OleDbConnection conn = new OleDbConnection(ConnString);
                OleDbCommand cmd = new OleDbCommand(SqlString, conn);
    
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("Phase", "Approved");
                //cmd.Parameters.AddWithValue("LastName", txtLastName.Text);
                
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (Exception exp)
            {
                Response.Write(exp.Message);
    
            } 
    
            DetailsView1.DataBind();
            GridView1.DataBind();
        }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
    
            //e.Row.Attributes.Add("onMouseOver", "this.style.background='#ff0000'");
    
            //e.Row.Attributes.Add("onMouseOut", "this.style.background='#ffffff'");
    
    
    
            if (e.Row.Cells != null && e.Row.Cells.Count > 1)
            {
                // assigns the index of the grid to a label
                lblIndex.Text = e.Row.Cells[1].Text.Trim();
                // shows the index being selected..works fine
                e.Row.Attributes.Add("onClick", "alert('Selected value: " + lblIndex.Text + "')");
    
    
            }
    
        }
     

Share This Page