Home > DeveloperSection > Forums > LINQ to SQL array list insertion
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    November-20-2014 10:40 PM

 ASP.Net ASP.Net  LINQ  SQL  Array 
Ratings:


 1 Reply(s)
 673  View(s)
Rate this:

how insert data array to database with linq to sql?

 

 DataClassesDataContext db = new DataClassesDataContext();

    simpleTbl tbl = new simpleTbl();

    string[] str =File.ReadAllLines(Server.MapPath("~/str.txt"));

 

    for (int i = 0; i <= 10; i++)

    {

       tbl.Name =str[i];

    }

  db.simpleTbl.InsertOnSubmit(tbl);

    db.SubmitChanges();

but dosen't work


How to do this?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    November-20-2014 11:48 PM

using(DataClassesDataContext db = new DataClassesDataContext())

{

    string[] strings = File.ReadAllLines(Server.MapPath("~/str.txt"));

    foreach (var str in strings )

    {

        db.simpleTbl.InsertOnSubmit(new simpleTbl(){ Name = str });

    }

    db.SubmitChanges();

}

You need to insert a new item for each entry in the string array


Don't want to miss updates? Please click the below button!

Follow MindStick