Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a column with a given name exists in a datarow

Tags:

vb.net

datarow

I want to insert a value from loop in datarow so before entering value in datarow, I want to check that a perticular column NAME exist in table or not.

Please tell me how can I check it. (vb.net preferred).

like image 283
Dr. Rajesh Rolen Avatar asked Dec 31 '09 10:12

Dr. Rajesh Rolen


People also ask

How to check if a column exists or not in SQL?

COL_LENGTH () function returns the defined length of a column in bytes. This function can be used with the IF ELSE condition to check if the column exists or not. Now we use the below query to check the existence of a column.

How to check if one or more columns all exist in Dataframe?

To Check If One or More Columns All Exist in DataFrame To check if one or more columns exist in pandas DataFrame, use a list comprehension, as in: For instance, if all ( [item in df.columns for item in ['Fee','Discount']]): . Yields same output as above.

How to check if a certain invoice exists in a column?

We want to check if a certain invoice exists in that column, and return “YES,” otherwise return #NA. We check this using MATCH and IF functions in Excel, such as. =IF (MATCH (D3,$A$2:$A$17,0),"Yes") This formula uses the MATCH function as a logical condition and If the MATCH function returns relative position of a value, ...

How to check if a value exists in a column using match?

Check if a value exists in a column using MATCH. Excel’s MATCH function searches for a value in a column or array and returns its relative position based on your chosen match type, whether exact or partial match. If the value is not found, then it returns a #NA error. Its syntax is: MATCH (value, array, [match_type])


3 Answers

I got the answer.and its working . its:

  If dr.Table.Columns.Contains("columnname") = True Then
   --your work---
  End If
like image 99
Dr. Rajesh Rolen Avatar answered Sep 22 '22 11:09

Dr. Rajesh Rolen


Try this

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

    End If
Next
like image 30
Anuraj Avatar answered Sep 23 '22 11:09

Anuraj


try:

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

 //....
like image 25
Leidr Garcia Avatar answered Sep 19 '22 11:09

Leidr Garcia