2009-12-31 16 views

Odpowiedz

16

Dostałem answer.and swoją pracę. jej:

If dr.Table.Columns.Contains("columnname") = True Then 
    --your work--- 
    End If 
+1

Ta część instrukcji '= True' nie jest konieczna. Metoda contains zwraca wartość boolean. – Quethzel

1

Spróbuj

Dim dt As New DataTable 
For Each dc As DataColumn In dt.Columns 
    If dc.ColumnName = "" Then 

    End If 
Next 
1

try:

 
if dr.Table.Columns("nameColumn") == null then 

//.... 
0

Oto kolejny sposób, aby dowiedzieć się, czy istnieje kolumna:

If dataRow.Table.Columns("ColumnName") IsNot Nothing Then 
    -- Your code if a column exists 
End If 

Zobacz this answer dla dalszego odniesienia, gdy takie podejście może być bardziej poręczne niż Contains("ColumnName") jeden.

1

Najkrótsze rozwiązanie.

If dr.Table.Columns.Contains("columnname") Then 
    'your code here 
End If 
Powiązane problemy