0

I seem to be running into this issue with inserting data into a table in a SQL Server 08R2 using LINQ in C#. No matter what I've tried I keep getting an error with INSERTONSUBMIT(). Here is the code...

private void testUpdateUNITBC()
{
      using (unitDataContext unit = new unitDataContext())
      {
            unitnotest unitbc = new unitnotest();
                 unit.FBARCO = "1234";
                 unit.FUNITNO = "1234";
                 unit.FJOBNO = "I9999-0000";
                 unit.FBOXNO = "999";
                 unit.FOPNO = "999";

             unit.UNITBCs.InsertOnSubmit(unitbc); <--this is where I get the error
       };

The error reads

void Table.InsertOnSubmit(UNITBC entity) Adds an entity in a pending insert state to this System.Data.Linq.Table. Error: The best overloaded method match for 'System.Data.Linq.Table.InsertOnSubmit(AS5553.UNITBC)' has some invalid arguments

The container I used to hold the variables matches the table datatypes. (string to varchar(64)) I know I need the unit.SubmitChanges(); next but it doesn't matter as I can't get passed the INSERTONSUBMIT() point. Any help would be great as I've tried several things and spent the entire day working on this with research.

Update

Here is the unitnotest class as requested...

    public class unitnotest 
{ 
     public string FBARCO {get;set;}
     public string FUNITNO {get;set;}
     public string FJOBNO {get;set;}
     public string FBOXNO {get;set;}
     public string FOPNO {get;set;}
}
hohner
  • 11,498
  • 8
  • 49
  • 84

1 Answers1

2

It seems that the EntityObject of type unitnotest is different from the EntityObject of the ObjectSet of type UNITBCs.

Means you are trying to insert the wrong object.

Akram Shahda
  • 14,655
  • 4
  • 45
  • 65
  • ok, that's what I thought; however, every example in the world shows inserting the container with the information as InsertOnSubmit(unitbc)... http://msdn.microsoft.com/en-us/library/bb386941.aspx per microsoft. Can you or anyone clarify on this for me? – saturnnine Feb 13 '13 at 14:44
  • @saturnnine the link you post: notice db.Orders / new order() versus in your case db.UNITBCs / new unitnotest() ; there is your difference – Pleun Feb 13 '13 at 14:47