October 25th, 2003, 03:53 AM
-
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
October 26th, 2003, 10:30 PM
-
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()
October 27th, 2003, 12:57 AM
-
thanks