Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
         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?
Posted
Updated 4-Sep-13 2:17am
v2

check this out, hope it gets you started.

http://stackoverflow.com/questions/8662752/insert-list-in-database[^]
 
Share this answer
 
Try this[^]
 
Share this answer
 
Loop through the list like below
C#
foreach(string item in myValues )
{
var value=item;
//insert the value to db here
}

Hope this helps
 
Share this answer
 
Comments
fasher_the_one 4-Sep-13 8:56am    
Jameel,
For example, my table that will receive the data table is called Y:
id_tabY is int identity,
string values​​,

My list is populated this way:
List <string> myValues ​​= new List () {"258632", "369856", "012345", "032165", "211458", "214563", "098796", "574623", "894235",
             "313569", "535458", "318954", "838692", "698562", "216898", "021214", "365652", "512489", "865412", "601221"};
values ​​in this list are string

I want to go through this list and add the data in Table Y. will look like after the code
foreach (string item in myValues​​)
{
var value = item;
/ / insert the value to db here
}

please help me with the code yet because I'm giving my first steps with asp.net.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900