ansari.wajid 0 Light Poster

Hi

I have gridview and I am using gridview1_rowupdating event to update the gridview, but when I am using the code given below its not working. I do not know why it is not updating, it is not even showing error. please help me resolve this problem.
Thanks

protected void gv_RowUpdating1(object sender, GridViewUpdateEventArgs e)
    {
        connectAccessDb();
        int i = e.RowIndex;
        //par = cmd.Parameters;
        //cmd.Parameters.Clear();
        string id = (gv.Rows[e.RowIndex].FindControl("lblCID") as Label).Text;
        string comp = (gv.Rows[e.RowIndex].FindControl("txtCName") as TextBox).Text;
        string address = (gv.Rows[e.RowIndex].FindControl("txtCAddr") as TextBox).Text;
        string city = (gv.Rows[e.RowIndex].FindControl("txtCcity") as TextBox).Text;
        //string strQuery="UPDATE companydetail SET companyname='" + comp + "',companyaddress='" + address + "',companycity='" + city + "' where id=" + Convert.ToInt32(id);
        //dCmd = new OleDbCommand(strQuery, cn);
        //dCmd = new OleDbCommand("UPDATE companydetail SET companyname=@comp, companyaddress=@address, companycity=@city where id=@id", cn);
        string strQuery = "UPDATE companydetail SET companyname=@comp, companyaddress=@address, companycity=@city where id=@id";
        cmd = new OleDbCommand(strQuery, cn);
        cmd.Parameters.Add("@id", OleDbType.Integer).Value = Convert.ToInt32(id);
        cmd.Parameters.Add("@comp", OleDbType.VarChar).Value = comp;
        cmd.Parameters.Add("@address", OleDbType.VarChar).Value = address;
        cmd.Parameters.Add("@city", OleDbType.VarChar).Value = city;

        cmd.ExecuteNonQuery();
        cmd.ExecuteNonQuery();
        //gv.EditIndex = -1;
        cn.Close();
        bindData();

      
    }
 private void bindData()
    {    
        connectAccessDb();
        da = new OleDbDataAdapter("SELECT id,companyname,companyaddress,companycity  from companydetail order by companyname", cn);       
        da.Fill(ds, "companydetail");
        gv.DataSource = ds;
        gv.DataBind();
        cn.Close();        
    }
private void connectAccessDb()
    {

        cn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" + strRootDir + "App_Data\\newsdb.mdb");
        cn.Open();
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.