I want to fill a drop down list with some data in a data source.
I defined a page level array and redim it in Page_Load.
I get an error saying
"Object reference not set to an instance of an object"
The error occurs at the statement,
Below is the code (I omitted unnesary HTML codes
for the presentation)
Can you please tell me how to correct this?
Thank you
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
dim strService(5) as string
sub Page_Load(obj as object, e as EventArgs)
dim objConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/scms/database/scms.mdb"))
dim objCmd as new OleDbDataAdapter("select * from services", objConn)
Dim cb as New OleDbCommandBuilder(objCmd)
dim ds as DataSet = new DataSet()
objCmd.Fill(ds, "services")
dim n as integer
n = ds.Tables("services").Rows.Count
redim strService(n)
dim i as integer
for i = 0 to n-1
strService(i) = ds.Tables("services").Rows(i)("ServceName").ToString
end sub
<title>Maintain Categories</title>
<link rel="stylesheet" type="text/css" href="support-files/main.css">
<form runat="server">
<asp:dropdownlist ID="lbService" DataSource='<%# strService %>' runat="server" />