I have made a class containing a sub which gets all records from a language database. My app is using user controls, so it essential for me only to maintain the code, which fetches the languages once because I have 76 user controls.
My class is:
From my app I try to run this class with this code:Code:Imports System.Data Imports System.Data.OleDb Public Class Language Inherits System.Web.UI.UserControl Dim strLangCn, strLang, langArr(100) As String Public x As Integer Public Sub getLanguage(ByVal value As String) strLangCn = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & Server.MapPath("language.MDB") & ";" Dim strSql As String = "Select * FROM LanguageTable ORDER BY id ASC" Dim objConnection As New OleDbConnection(strLangCn) Dim objCommand As New OleDbCommand(strSql, objConnection) Dim objDataReader As OleDbDataReader objConnection.Open() objDataReader = objCommand.ExecuteReader() strLang = value For x = 0 To objDataReader.FieldCount Do While objDataReader.Read() = True langArr(x) = CStr(objDataReader(strLang)) x += 1 Loop Next objDataReader.Close() objConnection.Close() End Sub End Class
But it doesn't work, the error is:Code:public sub test() language1.getLanguage("english") end sub
Object reference not set to an instance of an object.
in line 9 (the line with strLangCn)
Can anyone tell me, what's wrong?


Reply With Quote