Retrieving info out of a MDB

S

Scott M.

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 
J

John

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary? How would I link the Data adapters and data sets I created to this form?
 
J

John

When I click on the button, nothing happens, I dont know what is wrong

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 
R

RobinS

If you put a breakpoint in the code in the Button1_Click routine,
does it stop there? Or put a debug.writeline statement or something?
To tell you if it ever gets there?

Is this .Net 2003 or .Net 2005?
Robin S.
-------------
When I click on the button, nothing happens, I dont know what is wrong

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 
R

RobinS

What if you try just doing *one* read and filling the textboxes,
rather than looping through the data reader?

Robin S.
------------------------
The breakpoints happen within the button1_click routine, but not within;

While dr.Read()

TextBox1.Text = dr(0)

TextBox2.Text = dr(1)

TextBox3.Text = dr(2)

End While

I guess thats why the data is'nt being written, but I dont know how to re-write it to make it work.



If you put a breakpoint in the code in the Button1_Click routine,
does it stop there? Or put a debug.writeline statement or something?
To tell you if it ever gets there?

Is this .Net 2003 or .Net 2005?
Robin S.
-------------
When I click on the button, nothing happens, I dont know what is wrong

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 
J

John

The breakpoints happen within the button1_click routine, but not within;

While dr.Read()

TextBox1.Text = dr(0)

TextBox2.Text = dr(1)

TextBox3.Text = dr(2)

End While

I guess thats why the data is'nt being written, but I dont know how to re-write it to make it work.



If you put a breakpoint in the code in the Button1_Click routine,
does it stop there? Or put a debug.writeline statement or something?
To tell you if it ever gets there?

Is this .Net 2003 or .Net 2005?
Robin S.
-------------
When I click on the button, nothing happens, I dont know what is wrong

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 
C

Cor Ligthert [MVP]

John,

Wrote a complete solution in the other newsgroup you have posted too.

Cor
"John" <[email protected]> schreef in bericht The breakpoints happen within the button1_click routine, but not within;

While dr.Read()

TextBox1.Text = dr(0)

TextBox2.Text = dr(1)

TextBox3.Text = dr(2)

End While

I guess thats why the data is'nt being written, but I dont know how to re-write it to make it work.



If you put a breakpoint in the code in the Button1_Click routine,
does it stop there? Or put a debug.writeline statement or something?
To tell you if it ever gets there?

Is this .Net 2003 or .Net 2005?
Robin S.
-------------
When I click on the button, nothing happens, I dont know what is wrong

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 
W

Webuser

thank you
John,

Wrote a complete solution in the other newsgroup you have posted too.

Cor
"John" <[email protected]> schreef in bericht The breakpoints happen within the button1_click routine, but not within;

While dr.Read()

TextBox1.Text = dr(0)

TextBox2.Text = dr(1)

TextBox3.Text = dr(2)

End While

I guess thats why the data is'nt being written, but I dont know how to re-write it to make it work.



If you put a breakpoint in the code in the Button1_Click routine,
does it stop there? Or put a debug.writeline statement or something?
To tell you if it ever gets there?

Is this .Net 2003 or .Net 2005?
Robin S.
-------------
When I click on the button, nothing happens, I dont know what is wrong

After reading the tutorial from http://www.startvbdotnet.com/ado/msaccess.aspx I wrote this code in an attempt to get information from my MDB file called FillMe. The only table in that Access file is called MainTable;

Imports System.Data.OleDb

Public Class Form2
Inherits System.Windows.Forms.Form

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

'WINDOWS GENERATED

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub exitbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbutton.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\Name\Desktop\FillMe.mdb;")
'provider to be used when working with access database
cn.Open()
cmd = New OleDbCommand("select * from MainTable", cn)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
'loading data into TextBoxes by column index
End While
Catch
End Try
dr.Close()
cn.Close()
End Sub
End Class

Is filling the data set when the form loads neccisary?

You've got to fill it sometime, so why not Page_Load?

How would I link the Data adapters and data sets I created to this form?

OleDbDataAdapter1.Fill(DataSet11)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top