Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/forums/asp/)
-   -   I got a problem when updating a table in MS Access (http://www.go4expert.com/forums/i-updating-table-ms-access-t13059/)

Zazabazulla 19Aug2008 17:51

I got a problem when updating a table in MS Access
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:


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 +"';";
            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);
        catch (Exception exp)


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 + "')");



All times are GMT +5.5. The time now is 12:49.