how to check column name exist in datatable
  • how can i check that given column exist in datatable or nor because i am doing looping on dataset but when column not found in datatable so its throwing error.

    my code is this




    If (dset.Tables("DCDetail").Rows(e.RowHandle)(e.Column.FieldName) IsNot DBNull.Value And dset.Tables("DCDetailOld").Rows(e.RowHandle)(e.Column.FieldName) IsNot DBNull.Value) Then
    If (dset.Tables("DCDetail").Rows(e.RowHandle)(e.Column.FieldName) <> dset.Tables("DCDetailOld").Rows(e.RowHandle)(e.Column.FieldName)) Then
    'here is my code
    End If
    End If
  • 1 Comment sorted by
  • you can use Columns.Contains method for this task

    If dset.Tables("DCDetail").Columns.Contains(e.Column.FieldName) = True Then

                            If (dset.Tables("DCDetail").Rows(e.RowHandle)(e.Column.FieldName) IsNot DBNull.Value And dset.Tables("DCDetailOld").Rows(e.RowHandle)(e.Column.FieldName) IsNot DBNull.Value) Then
                                If (dset.Tables("DCDetail").Rows(e.RowHandle)(e.Column.FieldName) <> dset.Tables("DCDetailOld").Rows(e.RowHandle)(e.Column.FieldName)) Then
                                    e.Appearance.BackColor = Color.Red
                                    'e.Appearance.BackColor2 = Color.LightCyan
                                End If
                            End If

                        End If

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

    Optimum Creative