LINQ to SQL array list insertion

Manoj Bhatt

Total Post:154


Posted by  Manoj Bhatt
ASP.Net  LINQ  SQL  Array 
 1646  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];

but dosen't work

How to do this?

  1. Re: LINQ to SQL array list insertion

    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 });

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

      Modified On Apr-06-2018 11:52:54 PM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.