operator not defined for System.Data.SqlClient.SqlConnection and System.Data.SqlClient.SqlConnection

Posted by Beta033 on Stack Overflow See other posts from Stack Overflow or by Beta033
Published on 2010-04-19T18:04:32Z Indexed on 2010/04/20 13:23 UTC
Read the original article Hit count: 509

Filed under:
|

i hope i'm just doing something wrong here. Ideally i'm trying to open the connection, open a transaction execute a ton of prebuilt sqlstatements (with parameters) against this connection then close the connection. ideally all in the same batch.

It's easy enough to wrap this all in a for loop, however i'd like to use the forEach function of the list generic to set the connection as it'll probably be faster than my implementation of calling List.Item(i) in the loop but i get some strange errors.

 Dim sqlStatements As List(Of SqlCommand) = New List(Of SqlCommand)        
 Dim conn As SqlClient.SqlConnection = New SqlConnection("...")



 sqlStatements.Item(0).Connection = conn 
 'Works

sqlStatements.ForEach(Function(ByRef cmd As SqlCommand) cmd.Connection = conn)
 'ERROR: Operator '=' is not defined for types 
       'System.Data.SqlClient.SqlConnection'        
       'and 'System.Data.SqlClient.SqlConnection

What does this error really mean?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about .NET