如何从C#中的对象列表中删除空数据

时间:2018-09-20 12:38:48

标签: c# .net

我有一个SQL存储过程,该存储过程返回以下数据:

Id  data
1   {test12,sahjfh}
2   {test3,asfdssd}
3   null
4   null
5   {test454,aslkdfs}

我正在尝试使用下面的代码删除所有空值数据,但是它不起作用

public void TestMethod(){
// get the data from DB in list
            var InputList = new List<object>();
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {

                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "dbo.ReadAll_Input";

                    con.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            InputList.Add(dr["data"]);
                        }
                    }
                }
            }
            InputList.RemoveAll(data => data == null);


}

对此有任何提示吗?

谢谢!

0 个答案:

没有答案