我正在尝试编写使用用户输入来查询数据库然后在VB 2015中显示GridView的代码。我收到编译错误,无法弄清楚我做错了什么。
这是我的所有.VB编码。为了测试目的,我故意将变量设置为已定义的数字。
Imports System.Data
Imports System.Data.SqlClient
Partial Class BeaversInc_GridTest
Inherits System.Web.UI.Page
Dim strConnectionString As String
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim conn As New SqlConnection(strConnectionString)
Dim drDataReader As SqlDataReader
Dim dtDataTable As New DataTable
Dim cmd As New SqlCommand
Dim intStoreNumber As Integer
Dim dteStartDate As Date
Dim dteEndDate As Date
intStoreNumber = "686"
dteStartDate = CDate("11/15/2013")
dteEndDate = CDate("11/15/2015")
conn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
cmd.Connection = conn
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.CommandText = "CriticalFails"
With cmd.Parameters
.AddWithValue("@StoreNumber", intStoreNumber)
.AddWithValue("@StartDate", dteStartDate)
.AddWithValue("@Enddate", dteEndDate)
End With
conn.Open()
drDataReader = SqlCommand.ExecuteReader
dtDataTable.Load(drDataReader)
GridView1.DataSource = dtDataTable
GridView1.DataBind()
conn.Close()
End If
End Sub
End Class
答案 0 :(得分:0)
第" drDataReader = SqlCommand.ExecuteReader"不应该是" drDataReader = cmd.ExecuteReader" ??
我认为这是你的问题。 = d