IListSource不包含任何数据源

时间:2018-05-11 16:08:07

标签: vb.net iis aspxgridview

  • 想知道是否有人可以提供帮助? - 我使用.vb&amp ;;在VWD 2010中建立了一个网站。一切都在本地工作正常,但当我发布到IIS时,我收到一个错误:
  

System.Web.HttpException:IListSource不包含任何数据   源。

我检查过&对数据库的权限(据我所知很好 - 我甚至在数据库上使用它):

USE master
GO
sp_grantlogin 'IIS APPPOOL\DefaultAppPool'

USE AuditLogons
GO
sp_grantdbaccess 'IIS APPPOOL\DefaultAppPool', 'DefaultAppPool'

哪个工作正常 - 我觉得它应该有效但我对.VB&我希望真正做到这一点。 - 我已经google了很多&对web.config等进行了大量更改,但我确信它非常简单。 任何帮助将不胜感激,代码如下:

Imports System.Data
Imports System.Data.SqlClient
Imports System.IO

Partial Class _Default
Inherits System.Web.UI.Page
Private _getData As DataSet
Dim ds As Object

Private Property Yesterday As String
Private Property queryString As String

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    GridView1.PageIndex = e.NewPageIndex
    BindDataAllUsers()
    GridView1.DataBind()
End Sub

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Message.Text = ""
    If Not IsPostBack Then
        Yesterday = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd")
        StartDT.Text = Yesterday                 'DateTime.Now.ToString("yyyy-MM-dd")
        EndDT.Text = DateTime.Today.ToString("yyyy-MM-dd")
    End If
End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

End Sub

Protected Sub GetSingleUserBTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GetSingleUserBTN.Click
    Call BindDataSelectedUser()
End Sub

Protected Sub GetAllUsersBTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GetAllUsersBTN.Click
    Call BindDataAllUsers()
End Sub

Private Sub BindDataAllUsers()
    UserNM.Text = ""
    Message.Text = ""
    Dim StartDay As String
    Dim EndDay As String
    StartDay = StartDT.Text
    EndDay = EndDT.Text
    Dim StartMin As String
    Dim EndMin As String
    StartMin = " 00:00:00"
    EndMin = " 23:59:59"

    Dim queryString As String = "SELECT * FROM [AuditLogons].[dbo].[Logins] Where Timestamp between '" & StartDay & " " & StartMin & "' and '" & EndDay & " " & EndMin & "'"

    Dim ds As DataSet = GetData(queryString)

    GridView1.DataSource = ds
    GridView1.DataBind()
    GridView1.Visible = True

End Sub

Private Sub BindDataSelectedUser()
    Message.Text = ""
    Dim StartDay As String
    Dim EndDay As String
    StartDay = StartDT.Text
    EndDay = EndDT.Text
    Dim StartMin As String
    Dim EndMin As String
    StartMin = " 00:00:00"
    EndMin = " 23:59:59"

    If UserNM.Text = "" Then
        Message.Text = "You Must Enter a Username!"
        Exit Sub
    End If
    Dim queryString As String = "SELECT * FROM [AuditLogons].[dbo].[Logins] Where Username like '" & UserNM.Text & "' and Timestamp between '" & StartDay & " " & StartMin & "' and '" & EndDay & " " & EndMin & "'"

    Dim ds As DataSet = GetData(queryString)

    GridView1.DataSource = ds
    GridView1.DataBind()
    GridView1.Visible = True
End Sub


Function GetData(ByVal queryString As String) As DataSet

    Dim connectionString As String = ConfigurationManager.ConnectionStrings("AuditLogonsConnectionString").ConnectionString

    Dim ds As New DataSet()

    Try

        Dim connection As New SqlConnection(connectionString)
        Dim adapter As New SqlDataAdapter(queryString, Connection)

        Adapter.Fill(ds)


    Catch ex As Exception

        Message.Text = "Unable to connect to the database."

    End Try

    Return ds

End Function



Protected Sub RefreshBTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RefreshBTN.Click
    Message.Text = ""
    Response.Redirect(HttpContext.Current.Request.Url.ToString(), True)
End Sub

Protected Sub ExportBTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExportBTN.Click
    Dim strName As String
    If UserNM.Text = "" Then
        strName = "All_Users.xls"
    Else
        strName = UserNM.Text & ".xls"
    End If
    Try
        Response.Clear()
        Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment; filename=" & strName)
        Response.Charset = ""
        Response.ContentType = "application/vnd.ms-excel"
        Using sw As New StringWriter()
            Dim hw As New HtmlTextWriter(sw)
            GridView1.RenderControl(hw)
            Dim style As String = "<style> .textmode { } </style>"
            Response.Write(style)
            Response.Output.Write(sw.ToString())
            Response.Flush()
            Response.End()
        End Using
    Catch ex As Exception
        Message.Text = "Error exporting to Excel : " & ex.Message
    End Try


End Sub

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
End Class

非常感谢!

2 个答案:

答案 0 :(得分:0)

我假设数据集中有一个数据表,添加到BindDataAllUsers()

GridView1.DataMember = ds.Tables(0)

所以它写着:

GridView1.DataSource = ds
GridView1.DataMember = ds.Tables(0)
GridView1.DataBind()
GridView1.Visible = True

然而,jmcilhinney的观点很好,使用DataTable否定了对该行代码的需求。

答案 1 :(得分:0)

谢谢你,我把它改成了DataTable&amp;它现在按预期工作 - 非常感谢。