关于linq查询

lifelifelong 2010-07-17 12:16:03
我在admin数据库中有两行资料
1 luo luo
2 zhou zhou
在Linq查询语句中
var result = from v in bd.admin
select v;
int value = 0;
foreach (var v in result)
{
if (v.adminName == txtUserName.Text)
{
if (v.adminPassWord == txtPassWord.Text)
{
value = 1;
}
else
value = 2;
}
else value = 3;
}

为什么如果输入luo zhou的话,会查不到呢?虽然这是我想要的结果,但是逻辑上我好混乱啊,大家解答解答啊~~
我记得用sql语句查的,都貌似会查出 luo zhou 存在的。
...全文
59 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sunpire 2010-07-18
  • 打赏
  • 举报
回复
我不是说 Select * ,而是说在生成的 Sql 里面没有出现 Where 条件 , 这样相当于是每次都把整个表的全部行中的数据都查询了。
lifelifelong 2010-07-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sunpire 的回复:]
哪有这样子写 Linq 查询的啊,果然是混乱得不得了。

在调用 foreach 时,bd.admin 整个都被查询了,也就是相当于 Select * From admin , 这样哪有效率啊,连一个 Where 条件都没有。

在 v.adminName == txtUserName.Text 这句中, 执行的是 C# 中的字符比较,是区分大小写的。

“输入luo zhou” 这是……
[/Quote]

但是我需要表里面的所有数据啊,当然就用select了
Sunpire 2010-07-17
  • 打赏
  • 举报
回复
哪有这样子写 Linq 查询的啊,果然是混乱得不得了。

在调用 foreach 时,bd.admin 整个都被查询了,也就是相当于 Select * From admin , 这样哪有效率啊,连一个 Where 条件都没有。

在 v.adminName == txtUserName.Text 这句中, 执行的是 C# 中的字符比较,是区分大小写的。

“输入luo zhou” 这是指什么? 指“luo” 为txtUserName.Text , “zhou” 为 txtPassWord.Text 么子,这样当然查不到啦,因为LZ给出的两行数据中就没有符合要求的存在,效果相当于Sql
Select * From admin Where 用户名='luo' And 密码='zhou' ,而且还是区分大小写的。
LINQ is the part of the .NET Framework that provides a generic approach to querying data from different data sources. It has quickly become the next must-have skill for .NET developers. Pro LINQ: Language Integrated Query in C# 2010 is all about code. Literally, this book starts with code and ends with code. Most books show the simplest examples of how to use a method, but they so rarely show how to use the more complex prototypes. This book is different. Demonstrating the overwhelming majority of LINQ operators and prototypes, it is a veritable treasury of LINQ examples. Rather than obscure the relevant LINQ principles in code examples by focusing on a demonstration application you have no interest in writing, this book cuts right to the chase of each LINQ operator, method, or class. However, where complexity is necessary to truly demonstrate an issue, the examples are right there in the thick of it. For example, code samples demonstrating how to handle concurrency conflicts actually create concurrency conflicts so you can step through the code and see them unfold. Face it, most technical books, while informative, are dull. LINQ need not be dull. Written with a sense of humor, this book will attempt to entertain you on your journey through the wonderland of LINQ and C# 2010. What you’ll learn How to query Databases with LINQ to SQL, write your own entity classes, and understand how to handle concurrency conflicts. * How to leverage all the new LINQ relevant C# 2008 language features including extension methods, lambda expressions, anonymous data types, and partial methods. * How to use LINQ to Objects to query in-memory data collections such as arrays, ArrayLists, and Lists to retrieve the data you want. * Why some queries are deferred, how a deferred query can bite you, and how you can make deferred queries work for you. * How to use LINQ to XML to revolutionize your creation, manipulation, and searching of XML data. * How to query DataSets with LINQ to DataSet so you can coexist with legacy code and use LINQ to query databases other than SQL Server. Who is this book for? Apress, 2010 This book is written for the proficient C# developer, but you do not need to be up on all the latest C# features to understand the material. When you finish this book, you will have a much greater understanding of the latest C# features. amazon link:http://www.amazon.com/exec/obidos/ASIN/1430226536/buythisbooks-20

8,494

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧