vb.net - IListSource 不包含任何数据源
问题描述
- 想知道是否有人可以提供帮助?- 我已经使用 .vb 在 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 来说还是很新的,只想让它真正工作。- 我用谷歌搜索了很多,并对 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
非常感谢!
解决方案
我假设数据集中有一个数据表,添加到BindDataAllUsers()
GridView1.DataMember = ds.Tables(0)
所以上面写着:
GridView1.DataSource = ds
GridView1.DataMember = ds.Tables(0)
GridView1.DataBind()
GridView1.Visible = True
但是 jmcilhinney 的观点很好,使用 DataTable 否定了对那行代码的需要。
推荐阅读
- c# - SQL 如何替换一个值
- python - 使用 python 和请求,如何进行正确的 POST 调用以及在哪里找到标头?
- android - FirebaseAppDistribution:appDistributionUpload gradle 命令中缺少应用程序 ID
- mysql - 跨列和行计算值的实例
- javascript - 使用 redux 钩子时使用 redux 操作的最佳选择是什么?
- sql - Impala 2.11:AnalysisException:选择列表中不支持子查询
- swift - 在 SwiftUI 中获取当前的经纬度
- c++ - 是否可以禁止一个类被动态转换为?
- git - Git - 将发布分支合并到主分支
- tensorflow - 任何想法如何解决激活函数的问题?