Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error states: Object reference not set to an instance of an object

$
0
0
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            Dim MyConnection As SqlConnection
            Dim MyCommand As SqlCommand
            Dim MyReader As SqlDataReader

            MyConnection = New SqlConnection()
            MyConnection.ConnectionString = _
            ConfigurationManager.ConnectionStrings("SQLOLEDB.apxcs3.apsu.edu.wharper1").ConnectionString

            MyCommand = New SqlCommand()
            MyCommand.CommandText = "SELECT TOP 1 * FROM VISITS"
            MyCommand.CommandType = CommandType.Text
            MyCommand.Connection = MyConnection

            MyCommand.Connection.Open()
            MyReader = MyCommand.ExecuteReader(Commandbehavior.CloseConnection)
            dvVisits.DataSource = MyReader
            dvVisits.DataBind()

            MyCommand.Dispose()
            MyCommand.Connection.Dispose()
        End IfImports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            Dim MyConnection As SqlConnection
            Dim MyCommand As SqlCommand
            Dim MyReader As SqlDataReader

            MyConnection = New SqlConnection()
            MyConnection.ConnectionString = _
            ConfigurationManager.ConnectionStrings("SQLOLEDB.apxcs3.apsu.edu.wharper1").ConnectionString

            MyCommand = New SqlCommand()
            MyCommand.CommandText = "SELECT TOP 1 * FROM VISITS"
            MyCommand.CommandType = CommandType.Text
            MyCommand.Connection = MyConnection

            MyCommand.Connection.Open()
            MyReader = MyCommand.ExecuteReader(Commandbehavior.CloseConnection)
            dvVisits.DataSource = MyReader
            dvVisits.DataBind()

            MyCommand.Dispose()
            MyCommand.Connection.Dispose()
        End If

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>