Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.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
Asp.net 查询似乎不返回行,但在Access中返回_Asp.net_Sql - Fatal编程技术网

Asp.net 查询似乎不返回行,但在Access中返回

Asp.net 查询似乎不返回行,但在Access中返回,asp.net,sql,Asp.net,Sql,我使用querystring参数返回一个值,然后在下面的代码中使用该值: <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/TravelJoansDB.accdb" SelectCommand="SELECT * FROM [PeoplePhotos] WHERE ID = @ID"> <SelectParameters>

我使用querystring参数返回一个值,然后在下面的代码中使用该值:

<asp:AccessDataSource ID="AccessDataSource2" runat="server" 
    DataFile="~/App_Data/TravelJoansDB.accdb" 
    SelectCommand="SELECT * FROM [PeoplePhotos] WHERE ID = @ID">
    <SelectParameters>
        <asp:QueryStringParameter Name="ID" QueryStringField="ID" />                    
    </SelectParameters>
    </asp:AccessDataSource>
    <table class="picPageStyle">
        <tr>
            <td>
                <asp:Image ID="Image1" runat="server" BorderWidth="1px" ImageUrl='<%# "PlaceImages/" + Eval("picPath") %>' />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("picDesc") %>' />
            </td>
        </tr>
    </table>


当我在Access中用一个值替换“@ID”时,查询将很容易返回一行,并且它似乎(但似乎我错了)返回了该值,因为使用此代码的页面的地址显示了正确的ID,即“picpage.aspx?ID=4”,我缺少什么?它是否与querystring参数有关?

我不知道正确的解决方案

但是你可以这样试试

SelectCommand="SELECT * FROM [PeoplePhotos] WHERE ID =" + <%= Request.QueryString["ID"] %>>

必须将表格放置到FormView中:

<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource2">
    <ItemTemplate>
       <table class="picPageStyle">
         <tr>
           <td>
              <asp:Image ID="Image1" runat="server" BorderWidth="1px" ImageUrl='<%# "PlaceImages/" + Eval("picPath") %>' />
           </td>
         </tr>
         <tr>
            <td>
               <asp:Label ID="Label1" runat="server" Text='<%# Eval("picDesc") %>' />
            </td>
         </tr>
     </table>
    </ItemTemplate>
</asp:FormView>


Change Name=“ID”to Name=“@ID”@RameshRajendran我尝试将@符号放在两个不同的位置,但都无济于事。我似乎无法让它停止告诉我我需要正确的引号……嗯?所以正确的语法是SelectCommand=“SELECT*FROM[PeoplePhotos]其中ID=“++”>”???哦,我想你误解了我为什么要从“picPage.aspx?ID=4”开始。这是我在internet浏览器中单击上一页的链接时地址栏中的地址。如果我把整件事都包括进去,那就是“没关系!看到我更新的代码,你可以直接复制,然后通过那个答案,如果你有任何问题,然后告诉我。我粘贴了你的代码,它给我一个“服务器标签格式不正确”的错误,不会编译。
<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource2">
    <ItemTemplate>
       <table class="picPageStyle">
         <tr>
           <td>
              <asp:Image ID="Image1" runat="server" BorderWidth="1px" ImageUrl='<%# "PlaceImages/" + Eval("picPath") %>' />
           </td>
         </tr>
         <tr>
            <td>
               <asp:Label ID="Label1" runat="server" Text='<%# Eval("picDesc") %>' />
            </td>
         </tr>
     </table>
    </ItemTemplate>
</asp:FormView>