Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
note it is windows application.

in datagridview has follows;


Select Name Orderno OrderDate

Checkbox Ram 1 2/27/2013
Checkbox Sam 2 2/25/2013
Checkbox Vimal 3 2/28/2013
Checkbox suresh 4 2/26/2013


From the above record i select the first and last record in the datagridview using checkbox and want to save in the database.


Output i want to save in the Database as follows;

Name Orderno OrderDate

Ram 1 2/27/2013
suresh 4 2/26/2013


for the getting above output how to write the code in the save button using c sharp.

note it is windows application.

private void Btn_Save_Click(object sender, EventArgs e)
{

//in that what code i want to written so that the first and last record save in the Database
}
Posted

Hi..

Look into the below example:-

C#
protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {

            foreach (GridViewRow gr in gvAFBatProc.Rows)
            {
                sbQry.Clear();
                sbQry.Append("INSERT INTO " + dbName + "tbl<pre>&quot;
                sbQry.Append("(BID, BATCH_NO, LOAD_NO, SECTION_NO, LOT_NO) VALUES(");
                sbQry.Append(strBatchNo + ", "); 
                sbQry.Append(strBatchNo.Remove(0, 7).Trim() + ", "); 
                sbQry.Append("'" + ((Label)gr.FindControl("lblLoadNo")).Text + "', "); 
                sbQry.Append("'" + ((Label)gr.FindControl("lblSectionNo")).Text + "', "); 
                sbQry.Append("'" + ((Label)gr.FindControl("lblLotNo")).Text + "' "); 
                sbQry.Append(")");
                OraObj.ExecuteQry(sbQry.ToString());
            }
        }
        catch (Exception ex)
        {
        }
    }

<pre lang="c#">


Regards
Willington
 
Share this answer
 
hi,

you try

C#
for (int j = 0; j < this.datagridview1.RowCount; j++)
                    {
                        if (Convert.ToBoolean(this.datagridview1[0, j].Value) == true)
                        {
                            //save the values
                        }
                    }
 
Share this answer
 
v2
try this
C#
foreach (GridViewRow gr in datagridview.Rows)
            {
           CheckBox chkbox= datagridview.FindControl("NameOfCheckbox") as CheckBox; // find the check box 
                if (chkgvOverDue.Checked) // if Checked True
                {
                    //Save the Values Here
                }
  }
 
Share this answer
 
v2

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