#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    14
    Rep Power
    0

    Unhappy Object reference not set to an instance of an object


    hi, i hope u ppl will help me, i have made a class connectioncontrol and there is a method in that class namely sql_command(ByVal qq As String) but when i pass a string to this method i get the above mentionaed error
    the code is


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim cc As ConnectionControl

    Dim queryString As String
    queryString = "select * from t_category"
    cc.sql_command(queryString)
    DataGrid1.DataSource = cc.myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    DataGrid1.DataBind()
    cc.connection_close()
    End Sub



    Public Class ConnectionControl
    Dim myConnectionString As String
    Dim queryString As String
    Public myConnection As New SqlConnection()
    Public myCommand As New SqlCommand()

    Public Sub sql_command(ByVal qq As String)
    myConnectionString = "server=(local);database=e-auction;trusted_connection=true"
    myConnection.ConnectionString = myConnectionString
    myConnection.Open()
    myCommand.CommandText = qq
    myCommand.Connection = myConnection

    End Sub
    Public Sub connection_close()
    myConnection.Close()
    End Sub
    End Class
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Redmond, WA
    Posts
    218
    Rep Power
    15
    I don't code in VB.NET, but it doesn't look like you instantiated the ConnectionControl object. Try using the new keyword.
    Code:
    Dim cc As New ConnectionControl()
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    14
    Rep Power
    0
    thanks

IMN logo majestic logo threadwatch logo seochat tools logo