我的第一个linq连接,将无法连接到转发器

时间:2012-09-20 12:54:16

标签: asp.net vb.net linq

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

我创建了dbml文件,它名为“Thedatabaseconnection.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>

但是我无法将数据从数据库传输到转发器1 ...... 有人可以帮助我,这是我的第一个LinQ连接。

1 个答案:

答案 0 :(得分:0)

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

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

这将简单地呈现从DB返回的每个项目的信息和日期。如果需要,可以指定更复杂的标记。有关此主题的更多信息,请查看MSDN page about the Repeater control