Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/windows-phone-7/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 从Windows Phone本地数据库读取_Windows Phone 7_Windows Phone 7.1.1 - Fatal编程技术网

Windows phone 7 从Windows Phone本地数据库读取

Windows phone 7 从Windows Phone本地数据库读取,windows-phone-7,windows-phone-7.1.1,Windows Phone 7,Windows Phone 7.1.1,我的windows phone应用程序中有一个数据库。我需要从表中选择一些行。我需要在查询中应用多个Where条件。我如何编写这样的查询 我的表格包含用户名、文档ID、文件类型、文件位置、文件大小等 我需要使用用户名、文档ID和文件类型选择行。如何为此编写查询 现在我使用以下代码: using (DocumentDataContext DocDb = new DocumentDataContext(strConnectionString)) { IQueryable<Documen

我的windows phone应用程序中有一个数据库。我需要从表中选择一些行。我需要在查询中应用多个Where条件。我如何编写这样的查询

我的表格包含用户名、文档ID、文件类型、文件位置、文件大小等

我需要使用用户名、文档ID和文件类型选择行。如何为此编写查询

现在我使用以下代码:

using (DocumentDataContext DocDb = new DocumentDataContext(strConnectionString))
{
    IQueryable<Document> DocQuery = from Doc in DocDb.Documents where Doc.UserName == txtName.Text select Doc;
    Document Docs= DocQuery.FirstOrDefault();
}
使用(DocumentDataContext DocDb=new DocumentDataContext(strConnectionString))
{
IQueryable DocQuery=来自DocDb.Documents中的Doc,其中Doc.UserName==txtName.Text选择Doc;
Document Docs=DocQuery.FirstOrDefault();
}

我可以使用此查询选择一个文档。我想选择所有满足条件的行。我可以在一个查询中完成此操作吗?

当然可以。您可以使用标准或/和关键字扩展
where
条件:

from Doc in DocDb.Documents
where Doc.UserName == txtName.Text && dic.FileType == "some type" && Doc.UserName == "some name"
select Doc;
要获取多行,请使用而不是。它返回包含查询结果的元素列表:

var Docs= DocQuery.ToList();
我找到了解决办法

为了选择多个文档并在“WHERE”子句中应用多个条件,我对代码做了如下更改

IList<Document> DocumentList = null;

using (DocumentDataContext DocDb = new DocumentDataContext(strConnectionString))
{
    IQueryable<Document> DocQuery = from Doc in DocDb.Documents where Doc.UserName == txtName.Text & Doc.DocumentId == docId & Doc.FileType == fileType select Doc;
    DocumentList = DocQuery.ToList();
}
IList DocumentList=null;
使用(DocumentDataContext DocDb=newDocumentDataContext(strConnectionString))
{
IQueryable DocQuery=来自DocDb.Documents中的Doc,其中Doc.UserName==txtName.Text&Doc.DocumentId==docId&Doc.FileType==FileType选择Doc;
DocumentList=DocQuery.ToList();
}

在查询中,我首先使用“AND”在“WHERE”子句中添加更多条件。当我将“和”改为“&”时,它工作正常,并使用IList获取多条记录

感谢您的回答。但是在查询中使用“&”而不是“and”进行正确的操作,否则会出现以下错误“查询体必须以select子句或group子句结尾”。我问这个问题是因为这个错误。再次感谢。