none
LINQ Insert Identity Issue RRS feed

  • Question

  • hi all,

    i have a table called "TABLE1" it has an column User_Identity(Its a primary key, Identity Key). Im inserting some data to this table from C# using LINQ but, im not passsing data to User_Identity column(bcos its identity column) .

    First time insertion its working fine but, from nextt times im getting exception as " The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.  "

    If i delete the record from the Table1 and try to exceute my LINQ-C# code then this timme its working fine but, next time insertion the above same error came.

    below is my source code

    UserDataContext db = new UserDataContext(ConfigurationManager.ConnectionStrings["C288"].ConnectionString.ToString()); 
                    USER_MASTER um = new USER_MASTER 
                    { 
                        contact_person = txtContactPerson.Text.Trim(), 
                        client_compnay_name = txtClientCompanyName.Text.Trim(), 
                        adress = txtAddress.Text.Trim(), 
                        contact_details = txtContactDetails.Text.Trim(), 
                        website = Convert.ToString(txtWebsite.Text), 
                        e_mail_id = txtEMailID.Text.Trim(), 
                        security_question = ddlSecQues.SelectedItem.Text, 
                        security_answer = txtSecAns.Text.Trim(), 
                        add_date = DateTime.UtcNow.AddMinutes(330), 
                        ip = ip
    
                         
                    }; 
                    db.USER_MASTERs.InsertOnSubmit(um); 
                    db.SubmitChanges();

    experts please guide me, i confused much on this error.


    Thanks In Advance, Jeyaseelan

    Wednesday, December 12, 2012 3:05 PM

Answers

  • 1. i drop the table and recreated it

    2. deleted dbml file and recreated then drag and drop the same table

    now i dont see the issue, i used the same table structure,  same code but its working.


    Thanks In Advance, Jeyaseelan

    • Marked as answer by Jey-YoYo Friday, December 14, 2012 3:30 PM
    Friday, December 14, 2012 3:30 PM

All replies

  • experts please guide me to resolve this issue

    Thanks In Advance, Jeyaseelan

    Wednesday, December 12, 2012 4:27 PM
  • Hi Jeyaseelan,

    Welcome to the MSDN forum.

    Did you create the dbml from an existing databse? Or create the database via dbml?

    I tested the first scenario on my side, and it works great without assigning value of Primary key. Do you mind to make a test that please try to assign primary key value explicitly to check if this works or not?

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 9:33 AM
  • thanks for your response.

    i have created a new dbml file but, still i dont know why im getting this issue.


    Thanks In Advance, Jeyaseelan

    Thursday, December 13, 2012 10:01 AM
  • 1. i drop the table and recreated it

    2. deleted dbml file and recreated then drag and drop the same table

    now i dont see the issue, i used the same table structure,  same code but its working.


    Thanks In Advance, Jeyaseelan

    • Marked as answer by Jey-YoYo Friday, December 14, 2012 3:30 PM
    Friday, December 14, 2012 3:30 PM