473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

LINQ - Databinding questions

I have a form I'm playing around with that has some text boxes on it. I am
using SQL 2005 for my database.
I have a single table which I have created an object entity for. Customer

On the form I set the DataBindings Text value to "customerBindingSource -
CompanyName" on one of the textboxes.
The customerBindingSource was generated by the IDE and is pointing to the
Customer entity I created earlier. The CompanyName is a field within the
entity and underlying table.

During runtime I am using the follow code:

//----------------------------------------------------------------------------------
// This line is where my problem is.

this.CDC = new CustSiteDataContext(ConnString);
// Retreive customer record
var queryCust = from cust in CDC.Customers

where (cust.CustomerID == 100) && (cust.CompanyID == 5)

select cust;

this.customerBindingSource.DataSource = queryCust;

//----------------------------------------------------------------------------------

This works great, it reads the data in, I can make modifications and when I
click my button to save I execute:

this.CDC.SubmitChanges();

If the user wishes to abandon the changes, the idea is they can click a
button to do so. This code appears to work however I have to recreate a
new instance of the CustSiteDataContext for this to work.

In prior attempts I was looking at the refresh method, but I could not
figure out how to write it.
// CDC.Refresh(System.Data.Linq.RefreshMode.Overwrite CurrentValues);

Is the method I am using above the best/only way to implement "abandon"
changes ?

Thanks,

Dan
Sep 11 '08 #1
2 1915
Largely, yes. Getting a fresh data-context is the safest way of
ensuring you aren't keeping any abandoned changes. You shouldn't keep
a data-context around for too long anyway; they are intended to be
locally scoped, not last for the duration of an app.

Marc
Sep 12 '08 #2
Thanks for the response. My idea was to only keep the DataContext while the
user resides on that particular form. Its great to know I'm not completely
lost.

Thanks
Dan

"Marc Gravell" <ma**********@gmail.comwrote in message
news:31**********************************@26g2000h sk.googlegroups.com...
Largely, yes. Getting a fresh data-context is the safest way of
ensuring you aren't keeping any abandoned changes. You shouldn't keep
a data-context around for too long anyway; they are intended to be
locally scoped, not last for the duration of an app.

Marc

Sep 12 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
1
by: Frederik | last post by:
Hi all, Am I correct when stating that LINQ replaces somewhat DataTables? I have done some reading concerning LINQ, but I'm still puzzled as to whether I should use LINQ or not. My application...
1
by: Ilyas | last post by:
Hi all I have a database that contains several tables. Each table has the name data01, data02, data03 etc The column definitions for each table all contains several standard columns and then...
9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
7
by: shapper | last post by:
Hello, Is it possible to multiply all Prices in a List<Productby 1.1 using Linq? Product has a property named Price. Thanks, Miguel
2
by: shapper | last post by:
Hello, I have the following Linq query: List<PostsTaginsert = (from t in (from t in database.Tags join p in paper.Tags on t.Name equals p.Name select t).ToList() select new PostsTag {
4
by: CSharper | last post by:
I have following XML <root> <Person id="1"> <Name>a</Name> </Person> <Person id="2"> <Name>b</Name> </Person> </root>
4
by: George | last post by:
I am a bit conservative type and usually give some time for technology to mature before starting to try it. Today my question is Linq. To start using it or not. So here is the voting questions....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.