0

希望有人可以帮助我解决这个问题。我试图从 mdf 数据库中获取数据到转发器中。

我创建了名为“Thedatabaseconnection.dbml”的 dbml 文件,我有 web.config 文件,其中有一个名为“masterDBConnectionString”的连接字符串。

我有这个 vb 类文件。

Imports Microsoft.VisualBasic
Imports System.Web

Public Class connectionDBtesttable

Private _testId As Integer
Private _testCat As String
Private _testInfo As String
Private _testNumbers As Integer
Private _testDate As Date

Public Property test_id() As Integer
    Get
        Return _testId
    End Get

    Set(value As Integer)
        _testId = value
    End Set
End Property

Public Property test_cat() As String
    Get
        Return _testCat
    End Get

    Set(value As String)
        _testCat = value
    End Set
End Property

Public Property test_info() As String
    Get
        Return _testInfo
    End Get

    Set(value As String)
        _testInfo = value
    End Set
End Property

Public Property test_numbers() As Integer
    Get
        Return _testNumbers
    End Get

    Set(value As Integer)
        _testNumbers = value
    End Set
End Property

Public Property test_datetime() As Date
    Get
        Return _testDate
    End Get

    Set(value As Date)
        _testDate = value
    End Set
End Property

End Class

我有这个 code_behind

Imports System
Imports System.Linq

Partial Class _default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Call linqdb()
    End If
End Sub

Private Sub linqdb()
    Using datacontext As New ThedatabaseconnectionDataContext()
        Dim query = From a In datacontext.GetTable(Of testtable)() _
                    Order By a.test_id Descending _
                    Select a

        Repeater1.DataSource = query.ToList
        Repeater1.DataBind()
    End Using
End Sub

End Class

我有这个主页

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="_default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <asp:Repeater ID="Repeater1" runat="server">
    </asp:Repeater>
</div>
</form>
</body>
</html>

但我无法将数据库中的数据导入repeater1...有人可以帮我吗,这是我的第一个LinQ 连接。

4

1 回答 1

0

您尚未指定应为转发器中的每个项目呈现什么标记。例如,尝试如下更改您的标记:

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        Info: <%# Eval("test_info") %>
        Date: <%# Eval("test_datetime") %>
    </ItemTemplate>
</asp:Repeater>

这将简单地呈现从数据库返回的每个项目的信息和日期。如果您愿意,可以指定更复杂的标记。有关此主题的更多信息,您可以查看有关中继器控件的 MSDN 页面

于 2012-09-20T13:01:36.363 回答