如何将数据从DataTable转换为字符串列表? [英] How can i Convert Data from DataTable into String List?

查看:850
本文介绍了如何将数据从DataTable转换为字符串列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用Sql Database进行后端,我正在开发一些基于Windows应用程序的项目。在该应用程序中,我使用Datatable来从Sqldatabase中检索数据并尝试将该数据添加到字符串List中,但不幸的是它没有发生。请帮助

这里是代码....



Hi,
I am using Sql Database for backend and i am working on some project based on Windows application. In that application i am using Datatable in order to retrive data from Sqldatabase and trying to add that data in to string List, but unfortunetly its not happening. Please help
here is the Code....

List<string> viru = new List<string>().ToList();
        public void GetName()
        {
           
            //Reading Data from VirusDataBase

            connection.Open();
            SqlCommand commandObject = new SqlCommand("Select Virus_Name from Virus", connection);
            SqlDataAdapter sda = new SqlDataAdapter(commandObject);
            DataTable dtVirusList = new DataTable();


            sda.Fill(dtVirusList);
            connection.Close();
            if (dtVirusList.Rows.Count > 0)
            {
                viru..Add(dtVirusList.ToString());
            }
             
        }

推荐答案

改为使用arraylist。

use arraylist instead.
arraylist al =new arraylist();
 
foreach(datarow str in dtviruslist.rows)
{
   al.add(str["column_name"].tostring());
// otherwise add to your list ie. viru
}


尝试这个我希望它能帮到你



如何将DataTable转换为通用列表? [ ^ ]



<小>继续微笑:) :) :)快乐编码:)
Try this I hope it will help you

How do you convert a DataTable into a generic list?[^]

Keep smiling :):):) happy coding:)


这篇关于如何将数据从DataTable转换为字符串列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆