chrispaul8676 0 Light Poster

Hi, there,
i am coming up with a dropdownlist that needs to get list from the sql database. the dropdownlist must get its data from the database. i am getting error in this codes:
It says that it is not declared. at the same time i can not get the codes working. please help. i have very short time.
subnetsList.DataSource = reader
subnetsList.DataValueField = "NET_ID"
subnetsList.DataTextField = "NET_SUBNET"
subnetsList.DataBind()

<script runat="server">
    Protected Sub LoadSubnet(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            
            ' Define data objects
            
            Dim conn As SqlConnection
            Dim subnetsComm As SqlCommand
            
            Dim reader As SqlDataReader

            ' Read the connection string from Web.config
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("NNDS_IP").ConnectionString
            
            ' Initialize connection
            conn = New SqlConnection(connectionString)
            
            ' Create command for SubnetList
            subnetsComm = New SqlCommand("SelectSubnetList", conn)
            ' Specify we're calling a stored procedure
            subnetsComm.CommandType = System.Data.CommandType.StoredProcedure
                 
            ' Enclose database code in Try-Catch-Finally
            Try
                ' Open the connection
                conn.Open()
                
                ' Execute the subnet command
                reader = subnetsComm.ExecuteReader()
                ' Populate the list of subnets
                subnetsList.DataSource = reader
                subnetsList.DataValueField = "NET_ID"
                subnetsList.DataTextField = "NET_SUBNET"
                subnetsList.DataBind()
                ' Close the reader
                reader.Close()
              
            Finally
                ' Close the connection
                conn.Close()
            End Try
        End If
    End Sub
</script>

<asp:DropDownList ID="subnetsList" runat="server" AutoPostBack="True">
</asp:DropDownList>

GridView User Control:

<script runat="server">
    Protected Sub LoadList(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            
            Dim conn As SqlConnection
            Dim ipComm As SqlCommand
            Dim adapter As SqlDataAdapter
            Dim location As DataSet = New DataSet("location")
 
            ' Read the connection string from Web.config
            Dim connectionString As String = ConfigurationManager.ConnectionStrings("NNDS_IP").ConnectionString
 
            ' Initialize connection
            conn = New SqlConnection(connectionString)
 
            ' Create command for Student
            ipComm = New SqlCommand("SelectIP", conn)
            ' Specify we're calling a stored procedure
            ipComm.CommandType = CommandType.StoredProcedure
 
            Try
                ' Open the connection
                conn.Open()
            
                ' Execute the command
                adapter = New SqlDataAdapter
                adapter.TableMappings.Add("Table", "location")
                adapter.SelectCommand = ipComm
                adapter.Fill(location)
                
                ipComm.Parameters.Add("@net_id", SqlDbType.Int)
                
            
                ' Display the requested data                     
                ipList.DataSource = location.Tables(0)
                ipList.DataBind()
              
            Finally
                ' Close the connection
                conn.Close()
            End Try
        End If
    End Sub
</script>

<asp:GridView ID="ipList" runat="server">
</asp:GridView>
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.