再做一个网站,显示文章的页面做好了,显示图片的功能也能实现,但是有一个问题就是我在文章中显示的图片是我上传的所有图片,而不是和相关文章对应的图片。我在数据库中已经建立了文章和图片所在表的一对多的关系,有人说我可能数据连接的代码写的不对才导致的将全部图片都显示出来了,请各位指教,万分感激!!!!

解决方案 »

  1.   

    1.对应关系可能没写好
    2.SQL语句确实有问题
    没有代码,这样想的~
      

  2.   

    <asp:Repeater id="repeater3" runat="server">
                      <HeaderTemplate>
                        <table border="0" width="95%" cellpadding=0 cellspacing=0 align=center>
                      </HeaderTemplate>
                      <ItemTemplate>
                        <tr>
                          <td align=center>
                             <image src="<%# Container.DataItem("picaddr") %>" width="180" height="115" border=0 />
                             <font color="gray">[<%#Container.DataItem("picmemo")%>]</font>
                          </td>     
                     </ItemTemplate>
                     <SeparatorTemplate>
                     </SeparatorTemplate>
                     <FooterTemplate>
                        </table>
                     </FooterTemplate>
                    </asp:Repeater>
     <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                            DataFile="~/Blog.mdb" 
                            SelectCommand="SELECT [PicMemo], [LogID], [PicAddr] FROM [UserPhoto]">
                        </asp:AccessDataSource>
    这是repeater的代码
    Sub BindPhoto()
            Dim StrCnn As String
            Dim Cnn As OleDbConnection
            Dim Cmd As OleDbDataAdapter
            Dim DTable As New DataTable
            Dim Sql As String
            StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("blog.mdb")
            Cnn = New OleDbConnection(StrCnn)
            If Session("username") = "" Then
                theName = "hyh1203"
            Else
                theName = Trim(Session("username"))
            End If
            PathStr = Trim(theName) & "/photo/"
            Sql = "select top 3 id,'" & Trim(PathStr) & "'+ picaddr as picaddr,picmemo from userphoto order by ddate desc"
            Cnn.Open()
            Cmd = New OleDbDataAdapter(Sql, Cnn)
            Cmd.Fill(DTable)
            repeater3.DataSource = DTable
            repeater3.DataBind()
            Cnn.Close()
        End Sub
    这是链接数据库的代码,请各位帮忙看看病,谢谢啦~