简体   繁体   中英

error in check datagridview cell value empty or not

this code is error :

The given ColumnMapping does not match up with any column in the source or destination.

i have check column where is empty or not, but not work.

using (var bulkCopy = new SqlBulkCopy(destinationConnection))
{

    //THIS A MAPPING REPLACET WITH YOUR NEED
    for (int i = 0; i <18; i++)
    {
        if (datagridaddfield.Rows[i].Cells[1].Value != null)
        {
            bulkCopy.ColumnMappings.Add(datagridaddfield.Rows[i].Cells[0].Value.ToString(), datagridaddfield.Rows[i].Cells[1].Value.ToString());
            bulkCopy.DestinationTableName = "profile2";
            [...]

i want program check this line if (datagridaddfield.Rows[i].Cells[1].Value != null) but program not checking!

The problem is that you are passing wrong parameters to ColumnMappings.Add . What you are doing now is passing cell values which doesn't make sense to Column mapping. One of the overloads should be passed the columns indexes to map. You could also use column names. Check out SqlBulkCopyColumnMappingCollection.Add Method .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM