user2416047
user2416047

Reputation: 100

LINQ-to-SQL get Primary Key from Table

I am having some troubles figuring out why I receive a NullReferenceException when using this code:

entityCustomer customer = new entityCustomer { 
                              firstName = txtFName.Text, 
                              lastName = txtLName.Text, 
                              homeAddress = txtAddress.Text, 
                              phoneNumb = txtPhone.Text, 
                              emailAddress = txtEmail.Text 
                          };

custTable.InsertOnSubmit(customer);
dc.SubmitChanges();

I get the error on InsertOnSubmit. Here is my entity class:

http://pastebin.com/49RtamPN

I tried following https://stackoverflow.com/a/788402/2416047, as you can see, but still had no luck.

What am I doing wrong?

Upvotes: 0

Views: 742

Answers (1)

Arturo Martinez
Arturo Martinez

Reputation: 2583

Your custTable variable, parameter, property or field is null. You need to assign a value to it before calling any of its members.

Upvotes: 2

Related Questions