我有一个可能是一个非常简单的问题,但答案却完全逃离了我。我是 ASP.NET (vb) 的新手,但我有扎实的经典 ASP/VB 背景。
我有一个相对简单的数据库,它只包含四列(Language、SiteFooterPrivacyPolicy、SiteFooterTermsAndConditions、SiteFooterCopyright)。我希望执行一个只返回 1 行的查询。
这是到目前为止的主页(连同 SQL SELECT 语句):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="dbtest1.aspx.vb" Inherits="dbtest1" %>
<!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:SqlDataSource ID="MyLanguageDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [SiteFooterPrivacyPolicy], [SiteFooterTermsAndConditions], [SiteFooterCopyright] FROM [language_file_2] WHERE ([Language] = 'French')">
</asp:SqlDataSource>
<br />
<br /><b>Literal1PrivPolicy:</b> <asp:Literal ID="Literal1PrivPolicy" runat="server"></asp:Literal>
<br /><b>Literal2TermsConds:</b> <asp:Literal ID="Literal2TermsConds" runat="server"></asp:Literal>
<br /><b>Literal3Copyright:</b> <asp:Literal ID="Literal3Copyright" runat="server"></asp:Literal>
<br />
</div>
</form>
</body>
</html>
到目前为止,我有这段代码(不起作用),但希望它能比我能解释得更好,我想要实现的目标:
Partial Class dbtest1
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim dv As New Data.DataView
dv = MyLanguageDataSource.Select(DataSourceSelectArguments.Empty)
Literal1PrivPolicy.Text = dv.Table.Rows("SiteFooterPrivacyPolicy").ToString()
Literal2TermsConds.Text = dv.Table.Rows("SiteFooterTermsAndConditions").ToString()
Literal3Copyright.Text = dv.Table.Rows("SiteFooterCopyright").ToString()
End Sub
End Class
希望您能从中看到我正在尝试做的事情。我基本上需要用从我的数据库查询返回的正确列填充我的 Literal 元素。