且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将字符串转换为列表字符串

更新时间:2023-02-03 10:09:06

尝试:

 List< DataSet> liststring =  new  List< DataSet>(); 
...
liststring.Add(fieldFromDB2);


如果你要添加一个字符串,那么你需要一个字符串列表



列表< string> liststring =  new  List< string>(); 
liststring.Add(YourFieldAsString);


您好,

您的
列表< DataSet> liststring = new List< DataSet>(); 



是命名空间中的List(

 System.Collections.Generic; 



此列表中的每个项目都是数据集类型。

所以在命令中给它分配一个字符串值

你需要做什么类似这样的事情

 liststring [0] .Tables [0] .Rows [0] [0] = fieldFromDB2; 



在上面的语句中,我将此字符串

 fieldFromDB2 

分配给第一个数据集的第一个数据集集合中第一行的第一列,即

 liststring 





或者您需要在数据表中添加此

 fieldFromDB2 

然后在数据集中添加此表,然后使用

 liststring.Add(dataset)




br />
或者您需要更改

 List< DataSet> liststring = new List< string>(); 



然后

 liststring.Add(fieldFromDB2); 





希望这会对你有所帮助。

标记是否有用。



-

谢谢


Hi,

I am filtering the common msgIDs of 3 excel sheet columns with the following code
How can I place them into a list string


int  i = 2;
                    foreach (DataRow row in lstDS[2].Tables[0].Rows)
                    {


                        string fieldFromDB = row[1].ToString();
                        string FromDB = row[2].ToString();

                        foreach (DataRow row1 in lstDS[0].Tables[0].Rows)
                        {
                            string fieldFromDB1 = row1[1].ToString();

                            if (fieldFromDB == fieldFromDB1)
                            {

                                foreach (DataRow row2 in lstDS[1].Tables[0].Rows)
                                {
                                    string fieldFromDB2 = row2[1].ToString();

                                    if (fieldFromDB1 == fieldFromDB2)
                                    {

                                       //do something

                                    }



                                }
                            }
                        }
                    }



when I am trying to do something like this

List<DataSet> liststring = new List<DataSet>();<br />
liststring=fieldFromDB2;



It is giving some error like cannot convert string to list string


Thanks
John

Try:
List<DataSet> liststring = new List<DataSet>();
...
liststring.Add(fieldFromDB2);


If you are adding a string then you need a string list

List<string> liststring = new List<string>();
liststring.Add(YourFieldAsString);


Hi,
Your
List<DataSet> liststring = new List<DataSet>();


is a List from namespace (

System.Collections.Generic;

)
Each item in this list is of type Dataset.
So in an order to assign a string value to it
you need to do something like this

liststring[0].Tables[0].Rows[0][0] = fieldFromDB2;


Here in above statement I am assigning this string

fieldFromDB2

to first dataset's first table's first row's first column in your collection of datasets i.e.

liststring



Or either you need to add this

fieldFromDB2

in a datatable and then add this table in a dataset and then add this dataset in list
using

liststring.Add(dataset)



Or either you need to change

List<DataSet> liststring = new List<string>(); 


and then

liststring.Add(fieldFromDB2);



Hope this will help you.
Mark if useful.

--
Thanks