在C#中使用List [英] working with List in C#

查看:87
本文介绍了在C#中使用List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

 

我正在使用列表,我需要搜索这个问题:



我正在创建一个字符串类型的列表,其中包含从我的数据库中获取的数据的列表,如下所示:

hello guys,
 
I'm working with lists, where i had the need to search about this question:

I'm creating a list with string typed, where carry this list with data picked up from my database like this:

         SqlConnection conn = new SqlConnection (MyConection);
         Conex. Open ();

         SqlCommand comand = new SqlCommand ();
         comand.CommandText = "Select FROM TableX values​​";

         comand.Connection = conn;

         DrTest comand.ExecuteReader SqlDataReader = ();

         / / create the list
         List <string> myValues ​​= new List ();

         / / Fill the list with values ​​from the Bd
         while (drTest.Read ())
         {
             myValues​​. Add (drTest ["values"]. ToString ());
         }



这部分完美无缺。现在我需要执行反向过程,该过程在列表中获取值并插入到数据库中的表中。



任何帮助?


This part works perfectly. now i need to do the reverse process which is taking values ​​in a list and insert into my table in the database.

Any help?

推荐答案

看看这个,希望它能帮助你开始。



http://stackoverflow.com/questions/8662752/ insert-list-in-database [ ^ ]
check this out, hope it gets you started.

http://stackoverflow.com/questions/8662752/insert-list-in-database[^]


尝试这个 [ ^ ]


循环显示如下列表

Loop through the list like below
foreach(string item in myValues )
{
var value=item;
//insert the value to db here
}



希望这有助于


Hope this helps


这篇关于在C#中使用List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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