C# 查询sql获取List<int>

public static List<int> GetAllIDBySql(string strSql)
{
    List<int> lst = new List<int>();
    DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, strSql);
    if (ds.Tables[0].Rows.Count > 0)
    {
        if (ds.Tables[0].Columns.Contains("ID"))
        { 
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                lst.Add(int.Parse(dr["ID"].ToString()));
            }
        }
    }

    return lst;
}
posted @ 2021-10-16 11:18  673613920  阅读(473)  评论(0)    收藏  举报