"Field" is not a member of "System.Data.DataRow"

I am using VS2005 for vb.net. I get a compilation error in the instructions below. How to fix it?

For Each rw As DataRow In data.Rows For Each dc As DataColumn In stringColumns rw.Field(Of String)(dc).Replace("_x00D_", "") //Error showing here Next Next 
+6
source share
3 answers

Update 2: vote for another more direct / clear answer :-)


Update: while still applicable, there is a DataRow.Field provided by DataRowExtensions ; make sure it is referenced.


Since there is no element named Field defined by DataRow ... maybe a special Item instead?

Notice the example where it is used as an indexer ( row("Name") ). Neatly, huh?

(Also, something needs to be done with the Replace result, since strings are immutable in .NET.)

Happy coding.

+8
source

Add a link to System.Data.DataSetExtensions.dll , then your code will work. Field is an extension method that you need to add to the link, otherwise it will not work.

VS 2005 with .net 2.0?

then you cannot add a link to this dll. you need to target .net 3.5 or higher to use these extension methods.

+14
source

This error also occurs if you are not explicitly throwing a DataRow. (The original poster does it right.)

Use this:

 For Each rw As DataRow In data.Rows 

Not this:

 For Each rw In data.Rows 
+2
source

Source: https://habr.com/ru/post/916970/


All Articles