Jag använder mig av koden nedan samt en storedProcedure och jag vet inte om det är min storedprocedure eller vart felet sitter.HJÄLP!
Felmeddelande:
*Fill: SelectCommand.Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Private Sub PopulateRootLevel()
Dim sqlConnection = ConfigurationManager.AppSettings("DataNetConnectionString1")
Dim myCommand As New SqlCommand("dbo.StoredProcedure2", sqlConnection)
myCommand.CommandType = CommandType.StoredProcedure
Dim RootID As New SqlParameter("@sc.RootID", SqlDbType.Int)
Dim da As New SqlDataAdapter(myCommand)
Dim dt As New DataTable()
* da.Fill(dt)
PopulateNodes(dt, TreeView1.Nodes)
End Sub
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("Resorces").ToString
tn.Value = dr("RootID").ToString
nodes.Add(tn)
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
Min StoredProcedure
ALTER PROCEDURE dbo.StoredProcedure2
@Resorces nvarchar = 50, @RootID int OUTPUT
AS
SELECT RootID, Resorces,
(SELECT COUNT(*) FROM Tb_DataNet_Tree WHERE NodeID = sc.RootID) childnodecount
FROM Tb_DataNet_Tree sc WHERE NodeID IS NULL
/* SET NOCOUNT ON */
RETURN