LINQ TO SQL ARRAY LIST INSERTION

Total Post:154

Points:1086
ASP.Net  LINQ  SQL  Array 
 1302  View(s)
Ratings:
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?

  1. Post:378

    Points:2694
    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 });
        }
        db.SubmitChanges();
    }

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

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!