Hi all.

As mention on the title above, i got an error
Fill: SelectCommand.Connection property has not been initialized

Anyone here have any idea or suggestion on how to solve this error?

My code (.aspx.vb) for this program

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim i As Integer
        Dim result As DataSet
        Dim hypID As HyperLink
        Dim chkRemove As New CheckBox
        Dim clsPath As New Path()


            For i = 0 To grdPath.Rows.Count - 1
                chkRemove = DirectCast(grdPath.Rows(i).FindControl("chkRemove"), CheckBox)
                hypID = DirectCast(grdPath.Rows(i).FindControl("hypID"), HyperLink)

                If chkRemove.Checked Then

                    result = clsPath.getComparedPathID(chkRemove.Text)

                End If
            Next i
            lblErrorMessage.Text = "Paths delete successfully."
            BindGrid("%", "%", drpArea.SelectedValue, drpType.SelectedValue)
        Catch ex As Exception
            lblErrorMessage.Text = ex.Message
        End Try
    End Sub

And my .vb code is

    Public Function getComparedPathID(ByVal DeletePathID As String) As DataSet
        Dim DHHConn As New DRConnection("", "")
        Dim ds As DataSet

            ds = DHHConn.RunSPReturnDS("sp_Path_ID", New SqlParameter("@M_C", DeletePathID))
            Return ds
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Function

Recommended Answers

All 4 Replies


I don't see where you are setting your Connections connection string, you look to be passing in blank strings on the New DRConnection object (unless you are hiding the values your using for posting here.) so how does your DRConnection know what it is to connect to?

Hi G_Waddell :)

Yessss! This code are use for manage my database transactions

Dim DHHConn As New DRConnection("", "")

Actually, I has another class namely as DRConnection that stored all the function for this DRConnection to open and close the connection. I don't has any idea where to fixed this error.

Actually, this program works like this :

  1. user will choose path ID (retrieve all this data from table TPATH) that they want to delete.

  2. before the path ID would be delete, it will compare this path ID from table TTENS of database SDO and table TPATH of database SDO where this two table share the same column namely as M_C.

  3. this comparing method was write in Stored Procedure(SP).

    CREATE PROCEDURE [dbo].[sp_Path_ID] @M_C varchar(20)
        SELECT M_C FROM [dbo].[TPATH]
        and M_C = @M_C

and here the line where i'm call my SP

ds = DHHConn.RunSPReturnDS("sp_Path_ID", New SqlParameter("@M_C", DeletePathID))

  1. after done compared, then if path ID that user choose are not in table TTENS so, the path ID can be delete. But if path ID choose by user are in table TTENS, so the path ID cannot be delete.



My problem now :

  1. i'm not be able to compare this data
  2. i get this error Fill: SelectCommand.Connection property has not been initialized.

The issue appears to be that your program can not initialise the connection to the database.

When you initialise the DRConnection class should you not be passing in your connection string? does the DRconnection class have a default string value? Do you have to call an open connection on the class or does it open as part of the new sub?

Maybe include some of your DRConnection source code?

Hi G Waddell

I'm success to solved this error ! I added the parameter on this line :

Dim DHHConn As New DRConnection("", "DHHConn")

But, I still have problem on my SQL statement.

It cant compare the data before user able to delete it.

Ouh ya. Anyway, thank you for your guide ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.