tags:

views:

322

answers:

1

HI, I am trying to save some data to my .sdf file using a LinqToSql object. I have a table as follows -

PersonId int not null pk
forename nvarchar(4000)
surname nvarchar(4000)
Birthdate DateTime
IsMale bit
Biography nvarchar(4000)

I am inserting a value into all fields apart from the PersonId column (set to identity, increment).

I am using the C# code of

myLinqToSqlObject.Persons.InsertOnSubmit(thisPerson);

then

 thisDataContext.SubmitChanges();

and i get the exception of "Exception has been thrown by the target of an invocation." and an inner exception of just "Varchar"

Does anyone know what i'm doing wrong?

Thanks

EDIT - Showing code to populate thisPerson

thisPerson.Forename = thisDlg.Forename;
thisPerson.Surname = thisDlg.Surname;
thisPerson.Biography = thisDlg.Biography;
thisPerson.IsMale = thisDlg.IsMale;
thisPerson.BirthDate = thisDlg.BirthDate;

Where all fields return a value (no null values)

+1  A: 

Hey,

The DataContext has a Log property; if you assign a StreamWriter to it to write to a file, or attached Console.Out, it will write the SQL generated by the context, and you can better debug the query then potentially...

Also, to figure out what's going on, before submitting the changes, call context.GetChangeSet(),and use the immediate window and VS debugging to see what resides within this collection (it has the inserts, updates, and deletes being performed).

That will help you get to the answer quicker...

Brian
Thanks @Brian, how do i write it out to the console?
Ben