473,394 Members | 1,932 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,394 software developers and data experts.

i am new to linq to sql

Hi friends

i am using Linq to sql
and my code is

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class AccountSettings
  3.     {
  4.        NewCustomerDataContext _dbAccounts = new NewCustomerDataContext();
  5.  
  6.  
  7.        public int UpdateAccountSettigs(int iUserLoginID,string strUserMailID, string strPassword)
  8.        {
  9.  
  10.            var UpdateUser = _dbAccounts.UserLoginInfs.Single(e => e.UserLoginInfID == iUserLoginID);
  11.  
  12.  
  13.  
  14.            UpdateUser.UserMailID = strUserMailID;
  15.            UpdateUser.Password = strPassword;
  16.            _dbAccounts.SubmitChanges();
  17.  
  18.  
  19.  
  20.  
  21.  
  22.        }
  23.     }
  24.  

at the code

var UpdateUser = _dbAccounts.UserLoginInfs.Single(e => e.UserLoginInfID == iUserLoginID);

if no records are there with that criteria i am getting error.
so how do i validate this?

With earlier technology, when no records are found, we used to get 0 or something.

but how do we handle it in this case


also after executing
_dbAccounts.SubmitChanges();
how do i confirm that the update is success?
its return type is void
so how do i capture the result


thank you
Ravindar
Jun 26 '09 #1
1 1512
Curtis Rutland
3,256 Expert 2GB
There are two ways of going about this.
You could use a try/catch:

Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.   var UpdateUser = _dbAccounts.UserLoginInfs.Single(e => e.UserLoginInfID == iUserLoginID);
  4. }
  5. catch (Exception ex) //change this to the exact exception thrown
  6. {
  7.   //exception handling here
  8. }
Or you could do a count before you do your select:
Expand|Select|Wrap|Line Numbers
  1. var UpdateUser;
  2. if(_dbAccounts.UserLoginInfs.Count(e => e.UserLoginInfID == iUserLoginID) > 0)
  3.   UpdateUser = _dbAccounts.UserLoginInfs.Single(e => e.UserLoginInfID == iUserLoginID);
  4. else
  5.   //exception handling here
As to the last question, it will throw an error if unsuccessful. So you should probably catch that error and do something if it fails.
Jun 26 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dave Johnson | last post by:
Greetings, i want to be able to use linq new technology with sql server. the senario i am not able to do so far is as follow: 1- i program with linq 2- be able to generate and manipulate...
4
by: cj | last post by:
Can I use LINQ in VB .Net 2008 to get to a Visual FoxPro Table? I've seen demos of it with SQL Server but they've used it with a server browser and I don't think that'd work when I need to see VFP...
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...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
9
by: Cirene | last post by:
I'm about to begin a brand new, big, ASP.NET project (using 3.5 .net fw), VS 2008. I'm using MySQL as the backend (customer request.) I have absolutely no experience with LINQ and/or the Entity...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.