Solved

cannot update value - LINQ

Posted on 2009-04-07
4
205 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
ID: 24092909
0
 

Author Comment

by:manivineet
ID: 24093037
no that didn't help at all
0
 
LVL 21

Accepted Solution

by:
naspinski earned 500 total points
ID: 24094121
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
ID: 24134262
well the problem was that my table didn't have primary key.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

23 Experts available now in Live!

Get 1:1 Help Now