我在Visual Studio 2010中創建了一個網站。在網頁上,我想在gridview中顯示日期。當我去配置數據源時,我使用查詢生成器來獲取我想要的數據 - 即,我想顯示當前登錄的用戶的所有記錄。用戶從Windows登錄確定。我的選擇語句是:在網站的Gridview中選擇聲明不起作用
SELECT tblWorkHours.EmployeeName, tblWorkHours.BeginDateOff, tblWorkHours.EndDateOff,
tblWorkHours.AllDay_YesNo, tblWorkHours.BeginTimeOff, tblWorkHours.EndTimeOff,
tblWorkHours.Approved, tblCodesWork.Description, tblEmployees.Login FROM tblWorkHours INNER JOIN
tblCodesWork ON tblWorkHours.WorkCode = tblCodesWork.WorkCodeID INNER JOIN tblEmployees ON
tblWorkHours.Employee = tblEmployees.EmployeeID WHERE (tblEmployees.Login = @username) ORDER BY
tblWorkHours.BeginDateOff DESC
當我在配置數據源嚮導中測試查詢時,查詢返回正確的數據。當我運行網頁時,沒有gridview。我已經嘗試在網頁中添加一個字段,以確保我獲得了正確的用戶名,並且工作正常。我究竟做錯了什麼?任何幫助將不勝感激!
這裏是我的網頁代碼:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master"
CodeBehind="TimeOffAllByUser.aspx.vb" Inherits="timework.TimeOffAllByUser" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:BoundField DataField="EmployeeName" HeaderText="EmployeeName"
SortExpression="EmployeeName">
</asp:BoundField>
<asp:BoundField DataField="BeginDateOff"
HeaderText="BeginDateOff" SortExpression="BeginDateOff">
</asp:BoundField>
<asp:BoundField DataField="EndDateOff"
HeaderText="EndDateOff" SortExpression="EndDateOff">
</asp:BoundField>
<asp:CheckBoxField DataField="AllDay_YesNo" HeaderText="AllDay_YesNo"
SortExpression="AllDay_YesNo">
</asp:CheckBoxField>
<asp:BoundField DataField="BeginTimeOff"
HeaderText="BeginTimeOff" SortExpression="BeginTimeOff">
</asp:BoundField>
<asp:BoundField DataField="EndTimeOff"
HeaderText="EndTimeOff" SortExpression="EndTimeOff">
</asp:BoundField>
<asp:CheckBoxField DataField="Approved" HeaderText="Approved"
SortExpression="Approved">
</asp:CheckBoxField>
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description">
</asp:BoundField>
<asp:DynamicField DataField="Login" HeaderText="Login" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TimeSQLConnectionString1 %>"
SelectCommand="SELECT tblWorkHours.EmployeeName, tblWorkHours.BeginDateOff,
tblWorkHours.EndDateOff, tblWorkHours.AllDay_YesNo, tblWorkHours.BeginTimeOff,
tblWorkHours.EndTimeOff, tblWorkHours.Approved, tblCodesWork.Description, tblEmployees.Login
FROM tblWorkHours INNER JOIN tblCodesWork ON tblWorkHours.WorkCode = tblCodesWork.WorkCodeID
INNER JOIN tblEmployees ON tblWorkHours.Employee = tblEmployees.EmployeeID WHERE
(tblEmployees.Login = @username) ORDER BY tblWorkHours.BeginDateOff DESC" >
<SelectParameters>
<asp:QueryStringParameter Name="username"
QueryStringField="Split(HttpContext.Current.User.Identity.Name, quot;\", ,
CompareMethod.Text)"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
VB代碼是:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Mvc
Public Class TimeOffAllByUser
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim vusername() As String
vusername = Split(HttpContext.Current.User.Identity.Name, "\", , CompareMethod.Text)
'TextBox1.Text = (vusername(1))
End Sub
End Class
只是爲了檢查,你可以這樣改變,以瞭解這是否是問題報價? QueryStringField ='分割(HttpContext.Current.User.Identity.Name,「\」,, CompareMethod.Text)' –
不 - 沒有工作。感謝您的建議。還試過: – user3033348
糟糕 - 還試過:QueryStringField ='拆分(HttpContext.Current.User.Identity.Name," \ " ,, CompareMethod.Text)' – user3033348