Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > check if record exist

Reply
Thread Tools

check if record exist

 
 
Seema
Guest
Posts: n/a
 
      06-08-2009
What is the best way to check for a record exists in a database using linq to
sql?
I want to check if a userid (int) and typeid (int) exist. - The following
code always returns zero even if the record exists - what is the best
approach?

int result = 0
result = (from t in context.customers
where ((t.userid == intUserID) && (t.typeid ==
intTypeID))
select t).Count();
 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-08-2009
On Jun 8, 6:33*am, Seema <(E-Mail Removed)> wrote:
> What is the best way to check for a record exists in a database using linq to
> sql?
> I want to check if a userid (int) and typeid (int) *exist. - The following
> code always returns zero even if the record exists - what is the best
> approach?
>
> int result = 0
> result = (from t in context.customers
> * * * * * * * * * * * * * * * where ((t.userid == intUserID) && (t.typeid ==
> *intTypeID))
> * * * * * * * * * * * * * * * select t).Count();


var v = from t in context.customers where t.userid == intUserID &&
t.typeid == intTypeID select t;
bool exists = v.Count() == 0 ? false : true;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in logic populate Listbox if record does not exist in my Datagrid timcadieux ASP .Net 0 06-26-2008 08:53 AM
Does my object exist? So why its HWND doesn't exist? That's a question... (CMonthCalCtrl control) LT C++ 7 07-25-2004 07:08 PM
Can the Favourites Sidebar (IE, Opera, etc.) be addressed selectively (exist or non-exist)? Markus Mohr Javascript 7 11-28-2003 12:20 AM
In Schema, how to say "If one element exist, another element must exist"? Y.S. XML 3 09-17-2003 02:51 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM



Advertisments