Hi.
Got a small problem here. Trying to read data from an Access 2007 database but I'm getting nowhere.
What I do know is that everything is spelled correctly and that the database actually contains data.
I get no error and the form launches but the labeltext is not changed.
thanks
btw, Using VS 2008
this code doesn't work either:Code:Imports System.Data.OleDb Public Class Form1 Private conStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\SoccerQuiz.accdb;Jet OLEDB:Database Password=I_hate_Inter" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ReadData(conStr, "SELECT * FROM Tabell") End Sub Public Sub ReadData(ByVal connectionString As String, _ ByVal queryString As String) Using connection As New OleDbConnection(connectionString) Dim command As New OleDbCommand(queryString, connection) connection.Open() Dim reader As OleDbDataReader = command.ExecuteReader() While reader.Read() lblTest.Text = reader(0).ToString() 'Console.WriteLine(reader(0).ToString()) End While reader.Close() End Using End Sub End Class
Code:conn = New OleDbConnection(connstring) conn.Open() Dim cmd As New OleDbCommand(sql_query, conn) Try Dim reader As OleDbDataReader = cmd.ExecuteReader() While reader.Read() MessageBox.Show(reader.GetValue(0).ToString()) End While reader.Close() Catch err As OleDbException MessageBox.Show(err.Message) Finally conn.Close() End Try




Reply With Quote