Solved

cannot update value - LINQ

Posted on 2009-04-07
4
207 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

803 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