一个一个地引用视图值

Refering to view values one by one

我有以下代码在我正在处理的项目中建立 SQL 连接。我想要做的是创建一个 for 循环,其中包含一个方法,每次循环重复时,该方法都以不同的值运行,直到使用了返回查询的所有视图。

如果不先将视图保存到列表或数组,我不知道如何引用视图的每个值。有什么想法吗?

SqlConnection Con = new SqlConnection(@"Data Source=localhost\**;Initial Catalog=ML;User Id=sa;Password='**'");
string sql = @"select product_id,Name from E_PRODUCT_PROPERTY";
var mylist = new List<WineRating>();
using (var command = new SqlCommand(sql, Con))
{
    Con.Open();
    using (var reader = command.ExecuteReader())
    {
        while (reader.Read())
            new WineRating { product_id = reader.GetInt32(0), Name = reader.GetString(1) };                    

///Here goes the code I suppose

        method_name(reader.GetInt32(0), reader.GetString(1));

    }
}

public static int method_name(int product_id, string Name)
{
int num = x *2;
Console.WriteLine(num + Name);
}

大概是这样的:

using (var reader = command.ExecuteReader())
{
    while (reader.Read())
    {
        MyMethodToPrintToScreen(reader.GetInt32(0), reader.GetString(1));
    }
}

用打印到屏幕的方法

private static void MyMethodToPrintToScreen(int id, string product)
{
    //Do whatever you wish with the data: example
    Console.WriteLine($"My id: {id} | Product: {product}");
}

编辑
让我让它更明显(使用你的确切代码):

SqlConnection Con = new SqlConnection(@"Data Source=localhost\**;Initial Catalog=ML;User Id=sa;Password='**'");
string sql = @"select product_id,Name from E_PRODUCT_PROPERTY";
var mylist = new List<WineRating>();
using (var command = new SqlCommand(sql, Con))
{
    Con.Open();
    using (var reader = command.ExecuteReader())
    {
        while (reader.Read())
        {
            method_name(reader.GetInt32(0), reader.GetString(1));
        }
    }
}