首页 > 解决方案 > 插入多条记录以获取所有id时如何在c#中使用输出子句?

问题描述

在我的 c# 代码中,我有这个功能

public static List<T> SELECT<T>(string command, Func<SqlDataReader, T> f, Dictionary<string, object> h)
{
    SqlConnection myConnection = new SqlConnection(mySetting.ConnectionString);
    myConnection.Open();
    SqlDataReader myReader = null;
    SqlCommand myCommand = new SqlCommand(command, myConnection);
    foreach (KeyValuePair<string, object> entry in h)
    {
        myCommand.Parameters.AddWithValue(entry.Key, entry.Value);
    }
    myReader = myCommand.ExecuteReader();
    List<T> lst = new List<T>();
    while (myReader.Read())
    {
        lst.Add(f(myReader));
    }
    myConnection.Close();
    return lst;
}

但是如何使用其中的输出子句来获取表示 id 列表的整数数组?这是否支持临时表?

标签: c#sql-server

解决方案


推荐阅读