Data Platform Developer Center > Data Platform Development Forums > LINQ to SQL > Problem InsertOnSubmit - Linq - ( class inherited from identity class )
Ask a questionAsk a question
 

AnswerProblem InsertOnSubmit - Linq - ( class inherited from identity class )

  • Wednesday, October 28, 2009 11:19 PMbertoo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    In the code below I got an instantiating problem using Linq

    Context = using this method SetMappinImport , I got a sorted list cotaining the Column mapping between the columns of an external file and the members of the class "Artikel" which is inherited from the identity class "Bibliotheek" in the Datacontext (dbml )

    When I ran the solution I got an instantiating problem which I couldn't understand ...

    Somebody an idea why ? Thx in advance


    my code :

     

    public void SetMappinImport(DataSet ds, string tabelName, SortedList <string,string> mapping)

    {

     

    List<Artikel> artikelenImport = new List<Artikel>();

     

     

    DataClass.LqDataContext db = new DataClass.LqDataContext();

     

    switch

    switch

     

    (tabelName)

    {

     

    case "Bibliotheek":

     

    foreach (DataRow rw in ds.Tables[0].Rows)

    {

     

    Artikel art = new Artikel();

     

    int i = 1;

    i = ds.Tables[0].Columns.IndexOf(mapping[

    "Groep"]);

    art.Groep =

    Convert.ToString (rw[i]);

    i = ds.Tables[0].Columns.IndexOf(mapping[

    "Omschrijving"]);

    art.Omschrijving =

    Convert.ToString(rw[i]);

    i = ds.Tables[0].Columns.IndexOf(mapping[

    "PopCode"]);

    art.PopCode =

    Convert.ToString(rw[i]);

    i = ds.Tables[0].Columns.IndexOf(mapping[

    "Brutto"]);

    art.Brutto =

    Convert.ToString(rw[i]);

    i = ds.Tables[0].Columns.IndexOf(mapping[

    "Referentie"]);

    art.Referentie =

    Convert.ToString(rw[i]);

    i = ds.Tables[0].Columns.IndexOf(mapping[

    "Ve"]);

    art.Ve =

    Convert.ToString(rw[i]);

     

    db.Bibliotheeks.InsertOnSubmit(art);    //<-Object reference not set to an instance of an object ????? art !=null & db.Bibliotheeks !=null

    db.SubmitChanges();

    artikelenImport.Add(art);

    }

     

    //db.Bibliotheeks.InsertAllOnSubmit(artikelenImport ); ---> List<Artikel> arts

     

     

    break;

     


    case
    "Productlijnen":

     

     

     

    // to-do
    break
    ;

    }

     

     

    }

Answers

All Replies