"It is not possible to convert a lambda expression to enter" string "because it is not a delegate type" dataset request in C #

I have this code that compiles in VB.NET:

Imports System
Imports System.Data
Imports System.Data.Entity
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Collections
Imports System.Collections.Generic

Friend Module MainModule
    Friend Sub Main(args As String())
        Dim ds = GetSqlDataSet("", "")
        Dim allRows = From row In ds.Tables(0) Select row
    End Sub

    Private Function GetSqlDataSet(ByVal forQuery As String,
                                   ByVal withConnectionString As String,
                                   ByVal ParamArray withParameters As SqlClient.SqlParameter()) As DataSet

        GetSqlDataSet = New DataSet()

        Using conn As New System.Data.SqlClient.SqlConnection(withConnectionString)
            Using command As New System.Data.SqlClient.SqlCommand(forQuery, conn)
                command.Parameters.AddRange(withParameters)

                Using dataAdaptor As New System.Data.SqlClient.SqlDataAdapter(command)
                    dataAdaptor.Fill(GetSqlDataSet)
                End Using
            End Using
        End Using
    End Function
End Module

Here are the links:

enter image description here

Now I have what seems like the exact equivalent in C #:

using System;
using System.Data;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    internal static class MainEntryPoint
    {
        internal static void Main(string[] args)
        {
            var ds = GetSqlServerDataSet("", "");
            var allRows = from row in ds.Tables[0] select row;
        }

        public static System.Data.DataSet GetSqlServerDataSet(string usingQuery, 
            string usingConnectionString, params System.Data.SqlClient.SqlParameter[] withParameters)

        {
            var ret = new System.Data.DataSet();

            using (var conn = new System.Data.SqlClient.SqlConnection(usingConnectionString))
            {
                using (var command = new System.Data.SqlClient.SqlCommand(usingQuery, conn))
                {
                    command.Parameters.AddRange(withParameters);

                    using (var adapter = new System.Data.SqlClient.SqlDataAdapter(command))
                    {
                        adapter.Fill(ret);
                    }
                }
            }

            return ret;
        }
    }
}

And here are the links:

enter image description here

But I get this error:

enter image description here

I found a lot of resources that talk about adding link / use operators forSystem.Linq and as wellSystem.Data.Entity , but obviously I have those in both cases. Can someone please help me shed some light on this? Why does it work in VB.NET and not C #, and how do I get it to work in C #?

+4
source share
2

, VB DataTable. , :

Option Strict On

Imports System
Imports System.Data
Imports System.Linq

Public Class LinqTest

    Shared Sub Main()
        Dim table as DataTable = New DataTable
        Dim allRows = From row In table Select row
    End Sub

End Class

, ildasm , , DataTableExtensions.AsEnumerable() . , VB, , # . #.

+9

,

var allRows = from row in ds.Tables[0] select row;

var allRows = from row in ds.Tables[0].AsEnumerable() select row;

, VB , # , .

, DataSet.Tables DataTableCollection, IEnumerable, AsEnumerable().

, , !!!

+1

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


All Articles