LINQ TO SQL ARRAY LIST INSERTION

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
ASP.Net  LINQ  SQL  Array 
 990  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. Sumit Kesarwani

    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

Answer

NEWSLETTER

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