0

I am using Linq To Sql to insert few data to a table in Sql server 2008.

            memadd.add_id = Convert.ToDecimal(resadd);
            memadd.mem_add = txtResAdd.Text;
            memadd.tel_no1 =Convert.ToDecimal(txtResTelNo.Text);
            memadd.mob_no1 = Convert.ToDecimal(txtResMobNo.Text);
            memadd.state = drpResState.Text;
            memadd.city = drpResCity.Text;
            memadd.pin_no = Convert.ToDecimal(txtResPinNo.Text);
            dt.mem_addresses.InsertOnSubmit(memadd);
            dt.SubmitChanges(); 

My issue here is that when i insert data into the field , it gives me an error saying

Can't perform Create, Update or Delete operations on 'Table(mem_address)' because it has no primary key.

I have a situation wherein i cant set primary key to that table .Can anyone please point me out what needs to be done here. Thanks

1
  • Why is it that you can't set a primary key? Commented Mar 12, 2012 at 8:42

3 Answers 3

1

Just tell the memadd table in the DBML designer to select add_id as a PK for example.

It needs not be on the database itself.

Sign up to request clarification or add additional context in comments.

4 Comments

if i do that the add_id is going to be repeated like 1,2,3 then again 1,2,3 ,,, so do you think it would be feasible , doing that wont create problems ????
@freebird: Make it a composite key then to find some form of uniqueness.
,, can i set add_id as primary key in the designer and carry on or i should proceed as you suggested.. I dont know how to make it composite key.
@freebird: Just select both columns.
1

Linq to sql can't be used in such situations. Just warp your insert statement into a stored procedure and add the procedure to your data model. If you can't do that, write a normal function with a bit of in-line SQL

1 Comment

IIRC, I had no problem providing Linq2SQL with a 'pseudo' PK.
1

Linq does not support table w/o primary keys...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.