EDN Admin
Well-known member
im try using data reader on class but it doesnt work correctly. Here is my Class :<br/>
<pre class="prettyprint lang-vb Imports System.Data.OleDb
Public Class ClassDB
Protected myCMD As New OleDbCommand
Protected myCON As New OleDbConnection
Protected myDR As OleDbDataReader
Public Sub Connect()
Try
myCON = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Eatabase FileDatabase.mdb;Persist Security Info=True")
myCON.Open()
Catch ex As Exception
End Try
End Sub
Public Function ExDataReader(sqlString As String) As OleDbDataReader
Try
myCMD = New OleDbCommand(sqlString, myCON)
myDR = myCMD.ExecuteReader
Catch ex As Exception
End Try
Return myDR
End Function
Public ReadOnly Property GetDR
Get
Return myDR
End Get
End Property
End Class[/code]
and then i use that class to fill my list view <br/>
<br/>
<pre class="prettyprint lang-vb
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim myLV As ListViewItem
With ListView1
.Clear()
.GridLines = True
.View = View.Details
.Columns.Add("ID")
.Columns.Add("Nick")
.Columns.Add("Phone")
.Columns.Add("Mail")
.Columns.Add("Address")
End With
Dim myObject As New ClassDB
myObject.Connect()
Do While myObject.ExDataReader("SELECT * FROM MasterMember").Read
myLV = ListView1.Items.Add(myObject.GetDR.Item(0).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(1).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(2).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(3).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(4).ToString)
Loop
End Sub
End Class[/code]
there are 3 record(row) on that table but it show a thousands line with the same content. i try using data reader without using Class and it work correctly, the list view show 3 row. here code without Class :<br/>
<pre class="prettyprint lang-vb Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim myLV As ListViewItem
Dim myCMD As New OleDbCommand
Dim myCON As New OleDbConnection
Dim myDR As OleDbDataReader
Try
myCON = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Eatabase FileDatabase.mdb;Persist Security Info=True")
myCON.Open()
Catch ex As Exception
End Try
With ListView1
.Clear()
.GridLines = True
.View = View.Details
.Columns.Add("ID")
.Columns.Add("Nick")
.Columns.Add("Phone")
.Columns.Add("Mail")
.Columns.Add("Address")
End With
myCMD = New OleDbCommand("Select * From MasterMember", myCON)
myDR = myCMD.ExecuteReader
Do While myDR.Read
myLV = ListView1.Items.Add(myDR.Item(0).ToString)
myLV.SubItems.Add(myDR.Item(1).ToString)
myLV.SubItems.Add(myDR.Item(2).ToString)
myLV.SubItems.Add(myDR.Item(3).ToString)
myLV.SubItems.Add(myDR.Item(4).ToString)
Loop
End Sub
End Class[/code]
i just try fill a listview using datareader.<br/>
<br/>
View the full article
<pre class="prettyprint lang-vb Imports System.Data.OleDb
Public Class ClassDB
Protected myCMD As New OleDbCommand
Protected myCON As New OleDbConnection
Protected myDR As OleDbDataReader
Public Sub Connect()
Try
myCON = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Eatabase FileDatabase.mdb;Persist Security Info=True")
myCON.Open()
Catch ex As Exception
End Try
End Sub
Public Function ExDataReader(sqlString As String) As OleDbDataReader
Try
myCMD = New OleDbCommand(sqlString, myCON)
myDR = myCMD.ExecuteReader
Catch ex As Exception
End Try
Return myDR
End Function
Public ReadOnly Property GetDR
Get
Return myDR
End Get
End Property
End Class[/code]
and then i use that class to fill my list view <br/>
<br/>
<pre class="prettyprint lang-vb
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim myLV As ListViewItem
With ListView1
.Clear()
.GridLines = True
.View = View.Details
.Columns.Add("ID")
.Columns.Add("Nick")
.Columns.Add("Phone")
.Columns.Add("Mail")
.Columns.Add("Address")
End With
Dim myObject As New ClassDB
myObject.Connect()
Do While myObject.ExDataReader("SELECT * FROM MasterMember").Read
myLV = ListView1.Items.Add(myObject.GetDR.Item(0).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(1).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(2).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(3).ToString)
myLV.SubItems.Add(myObject.GetDR.Item(4).ToString)
Loop
End Sub
End Class[/code]
there are 3 record(row) on that table but it show a thousands line with the same content. i try using data reader without using Class and it work correctly, the list view show 3 row. here code without Class :<br/>
<pre class="prettyprint lang-vb Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim myLV As ListViewItem
Dim myCMD As New OleDbCommand
Dim myCON As New OleDbConnection
Dim myDR As OleDbDataReader
Try
myCON = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Eatabase FileDatabase.mdb;Persist Security Info=True")
myCON.Open()
Catch ex As Exception
End Try
With ListView1
.Clear()
.GridLines = True
.View = View.Details
.Columns.Add("ID")
.Columns.Add("Nick")
.Columns.Add("Phone")
.Columns.Add("Mail")
.Columns.Add("Address")
End With
myCMD = New OleDbCommand("Select * From MasterMember", myCON)
myDR = myCMD.ExecuteReader
Do While myDR.Read
myLV = ListView1.Items.Add(myDR.Item(0).ToString)
myLV.SubItems.Add(myDR.Item(1).ToString)
myLV.SubItems.Add(myDR.Item(2).ToString)
myLV.SubItems.Add(myDR.Item(3).ToString)
myLV.SubItems.Add(myDR.Item(4).ToString)
Loop
End Sub
End Class[/code]
i just try fill a listview using datareader.<br/>
<br/>
View the full article