Retriewing data from class
I have a problem. I can't fetch my data located in a class to my webform. I have no problems using SQL-server, but it doesn't work when I use an Access database.
This is my class:
Code:
Imports System.Data
Imports System.Data.OleDb
Public Class clsLanguage
Inherits System.Web.UI.UserControl
Dim strLang, langArr(100) As String
Public x As Integer
Public Function getLanguage(ByVal language As String) As String()
Dim strLangCn As String = "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()
Do While objDataReader.Read() = True
langArr(x) = CStr(objDataReader(language))
x += 1
Loop
objDataReader.Close()
objConnection.Close()
Return langArr
End Function
End Class
And this is my webform:
Code:
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim voresKunder As String()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim test As New clsLanguage
voresKunder = test.getLanguage("english")
Dim kunde As String
For Each kunde In voresKunder
Try
ListBox1.Items.Add(kunde)
Catch ex As Exception
Exit For
End Try
Next
End Sub
End Class
I have attatched a zip file including the project with database