Solved

cannot update value - LINQ

Posted on 2009-04-07
4
204 Views
Last Modified: 2013-11-11
I want update a property in a table (i' am using MS SQL server database) , but it get this error
" THIS PROPERTY IS READONLY"

how do i fix this?

also when I declare  a new linq database instance,
Dim Db As New SageEMSArchiveDataContext
I only get 4 overidable properties (normally this is 5)

I have
import  system.linq

I have checked my references, also stangely another project(on my system) does not have this issue.

any idea why this happens?




Dim Db As New SageEMSArchiveDataContext("Data Source=ADELN250;Initial Catalog=SageEMS;Integrated Security=True")
 

        Dim tbFile = (From files In Db.tbFiles _

                   Select files.Filename, files.ArchiveLocation Where Filename = fName).ToList(0)
 

        If Not tbFile Is Nothing Then

            tbFile.ArchiveLocation = "asdf" 'AT THIS POINT I GET AN ERROR SAYING THAT THIS PROPERTY IS READONLY

        End If

Open in new window

0
Comment
Question by:manivineet
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Sreedhar Vengala
Comment Utility
0
 

Author Comment

by:manivineet
Comment Utility
no that didn't help at all
0
 
LVL 21

Accepted Solution

by:
naspinski earned 500 total points
Comment Utility
It is because you aren't selecting the whole item, just a few fields.  If you select a few fields, it is just for reading, as each entity does not have a key to tell the DB which one it is.  Just change

Dim tbFile = (From files In Db.tbFiles _
                   Select files.Filename, files.ArchiveLocation Where Filename = fName).ToList(0)

to
Dim tbFile = From files In Db.tbFiles _ files

Open in new window

0
 

Author Comment

by:manivineet
Comment Utility
well the problem was that my table didn't have primary key.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now