How to add comma separated string into datatable in c#?

后端 未结 4 1915
北荒
北荒 2020-12-21 13:14

Let\'s consider I have two comma separated strings as written below.

string name = \"A,B,C,D\";
string value = \"100,200,300,400\";

So I wa

4条回答
  •  轮回少年
    2020-12-21 14:11

    Try something like this:

    DataTable table = new DataTable();
    table.Columns.Add("name", typeof(string));
    table.Columns.Add("value", typeof(string));
    
    string name = "A,B,C,D";
    string value = "100,200,300,400";
    
    string[] names = name.Split(',');
    string[] values = value.Split(',');
    
    for(int i=0; i

    But you should implement some validation code to make it more appropriate.

提交回复
热议问题