You must Sign In to post a response.
  • Category: Windows

    How yo add new row for data grid view and updated same id in c# windows application

    I am creating windows application using c# 2010, here i am using data grid view for billing purpose, once i am stored the values to database, and then after some time i am retrieve my first bill values and i am doing some changes and update the records for same bill number. Here i am not using text boxes i want update only my date grid view.

    How to write update query any one give me ideas.
  • #767394
    Hi,

    You can use Gridview RowEditing event for edit the records and for update the modified content into database you can use RowUpdating event, please refer below sample code for your reference.


    protected void GV_RowEditing(object sender, GridViewEditEventArgs e)
    {
    GV.EditIndex = e.NewEditIndex;
    Bind_GV();
    }
    protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    int EmpNo = Convert.ToInt32(GV.Rows[e.RowIndex].Cells[0].Text);
    TextBox EName = (TextBox)GV.Rows[e.RowIndex].Cells[1].Controls[0];
    TextBox Job = (TextBox)GV.Rows[e.RowIndex].Cells[2].Controls[0];
    TextBox Mgr = (TextBox)GV.Rows[e.RowIndex].Cells[3].Controls[0];
    //In edit mode also we give fileupload to upload new image and save that while update the row infomration.

    try
    {
    con.Open();
    cmd = new SqlCommand("Update_Employee_Details", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@EMPNO", EmpNo);
    cmd.Parameters.AddWithValue("@Ename", EName.Text);
    cmd.Parameters.AddWithValue("@Job", Job.Text);
    cmd.ExecuteNonQuery();

    GV.EditIndex = -1;
    Bind_GV();
    }
    catch (Exception ex)
    {
    }
    finally
    {
    con.Close();
    con.Dispose();
    }
    }


    Hope this will helpful to you..

    Refer below link for more details, http://www.dotnetspider.com/resources/45091-Insert-Edit-Update-Delete-Get-back-Image-from-DataBase.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #767425
    Sir this is not web application, this is for windows application.

    Give me some ideas.


  • Sign In to post your comments