我的查询工作在Access中,而不是在Visual Studio [英] My query works in Access, but not in Visual Studio

查看:132
本文介绍了我的查询工作在Access中,而不是在Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的访问似乎并不当我执行它在我的网站网站运行已经运行查询。这里的code代表我想要的数据库来填充内容网页:

I have a query that I have run in Access that doesn't seem to run when I execute it on my website site. Here's the code for the webpage that I want the database to populate content for:

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                        DataFile="~/App_Data/TravelJoansDB.accdb" 
                        SelectCommand="SELECT * FROM [Table2] INNER JOIN BlogEntryItems ON Table2.ID=BlogEntryItems.BlogID AND Table2.ID=@ID">
                        <SelectParameters>
                            <asp:QueryStringParameter Name="ID" QueryStringField="Table2.ID" Type="Decimal" />                    
                        </SelectParameters>
                        </asp:AccessDataSource>

    <asp:DataList ID="DataList1" DataSourceID="AccessDataSource1" 
            runat="server" ItemStyle-CssClass="picTableStyle"
            DataKeyField="Table.2ID">
            <ItemStyle></ItemStyle>
            <ItemTemplate>
                <table>
                   <tr>
                      <td>
                         <asp:Image ID="Image1" runat="server" ImageUrl='<%# "PlaceImages/" + Eval("Image") %>' /><br />
                         <asp:Label ID="Label1" CssClass="picCaptionStyle" runat="server" Text='<%# Eval("Caption") %>' />
                      </td>
                   </tr>
                   <tr>
                      <td>
                      <asp:Label ID="Label4" class="picBodyText" runat="server" Text='<%# Eval("PicStory") %>' />
                      </td>
                   </tr>
                </table>
            </ItemTemplate>

    </asp:DataList>

当我拿出的加入,它工作正常。我想补充的连接,它并没有给我任何错误或任何东西,只是好像没有结果它显示在我的网站。任何想法?

When I take out the join, it works fine. I add the join and it doesn't give me any error or anything, it just seems as though there are no results for it to show on my website. Any ideas?

推荐答案

请注意,我没有对的AccessDataSource 工作。然而,看着文档 - 这里是你应该看看到什么

Note that I haven't worked on AccessDataSource. However, looking at the docs - here is what you should look into


  • 更改查询使用?而不是@ID结果
    的SelectCommand =SELECT * FROM [表2] INNER JOIN BlogEntryItems ON Table2.ID = BlogEntryItems.BlogID AND Table2.ID =?

  • Change the query to use ? instead of @ID
    SelectCommand="SELECT * FROM [Table2] INNER JOIN BlogEntryItems ON Table2.ID=BlogEntryItems.BlogID AND Table2.ID= ?"

由于AccessDataSource控件扩展类的SqlDataSource
  并使用System.Data.OleDb提供,您指定的参数
  使用占位符?占位符。

Because the AccessDataSource control extends the SqlDataSource class and uses the System.Data.OleDb provider, you specify parameter placeholders using the "?" placeholder character.

REF:的http:// MSDN。 microsoft.com/en-us/library/8e5545e1%28v=vs.100%29.aspx


  • 如果以上不工作,忽略数据类型参数(小数),或者指定相关的类型,如整数代替。

  • If the above doesn't work, omit the data type (Decimal) of the parameter OR specify a relevant type such as Integer instead.

这篇关于我的查询工作在Access中,而不是在Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆