Reputation: 7006
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
Upvotes: 0
Views: 250
Reputation: 117340
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.
Upvotes: 1
Reputation: 6159
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
Upvotes: 1