Darrell Embrey
Darrell Embrey

Reputation: 21

Updating Database From Data Grid View Modified Rows c#

I am working in C#. I have a windows form with a data grid view that lists items for the user to review. The data source for the data grid view is a data table

public DataTable GetSFNoDFInventory()
{
    // DECLARATIONS
    using (DataTable toReturn = new DataTable())
    {
        //string updateProcName;
        //SqlCommand cmdUpdate;

        // Create and prepare a command object to be used for the SELECT statement of the data adapter.
        using (SqlCommand cmdSelect = new SqlCommand
        {
            Connection = new SqlConnection(ConString),
            CommandType = CommandType.StoredProcedure,
            CommandText = "usr.uspSFNoDFGetInventoryReview"
        })
        {
            using (SqlDataAdapter da = new SqlDataAdapter(cmdSelect))
            {
                da.Fill(toReturn);
            }
        }
        return toReturn;
    }
}

The rows in the data grid view have two check boxes for the user to select to update the row. One check box drops the row from further processing. The other flags the record to be included in an email message. I'm trying to collect the updated rows to update the SQL database table using a data view and SQL data adapter.

        private void btnSaveDropsAndEmails_Click(object sender, EventArgs e)
        {
            DataView vwDropSCCF = new DataView(Shared.DtReviewClaims.DefaultView.ToTable("drpSCCF"), "DropRcd = 1", "", DataViewRowState.ModifiedCurrent);

            if (dgReviewClaims.EndEdit())
            {
                Shared.SqlWrapper.UpdateDropEmail(vwDropSCCF);
            }
        }

However, the count property for vwDropSCCF is zero (0). What am I doing wrong?

Upvotes: 1

Views: 91

Answers (0)

Related Questions