migrating subs and procedures to classes and modules

  • Thread starter Thread starter dennist
  • Start date Start date
D

dennist

please excuse my last post on this which was improperly
formatted due to a utility(text cleaner) that I had
active.

My problem is that I read ado.net step by step, including
working out all the examples.

In the end, I still can't create generic procedures in
classes and modules.

I'm going to give you part of an example from vb 6, and
ask if you can show me how to do such things in ado.net

Private Sub Form_Load()

'InitcboQualifier
'Set clsTFSADO = New clsADO
Dim lPrntID As Long
Dim sItemText As String
lPrntID = clsTFSADO.ParntID

Me.Save0 = False
txtTopicTitle.Text = ""
mskDate = Date
cmdSaveLOG.Enabled = True
ComboBoxConnection
'SetcboQualifier "POV", "PermissionID"

clsTFSADO.FillComboBox cboTopicIssuer, "SELECT
TopicIssuers.* FROM TopicIssuers ORDER BY
TopicIssuers.Issuer;", 2

clsTFSADO.FillComboBox cboPublication, "SELECT
Publications.ID, Publications.Publication FROM
Publications ORDER BY Publications.Publication;", 2

sItemText = GetItemText(cboTopicIssuer, cboPublication)

' clsTFSADO.FillListBox lstAuthors, "SELECT Authors.ID,
Authors.[Last Name], Authors.[First Name] AS Name FROM
Authors ORDER BY Authors.[Last Name], Authors.[First
Name];", 1

clsTFSADO.FillListBox lstAuthors, "SELECT Authors.ID,
Authors.[Last Name], Authors.[First Name] FROM Authors
ORDER BY Authors.[Last Name], Authors.[First Name];", 1

sItemText = clsTFSADO.GetLItemText(cboPublication,
lstAuthors)

clsTFSADO.FillComboBox cboPOV, "SELECT PointsOfView.ID, "
& "PointsOfView.PointOfView FROM PointsOfView ORDER BY
PointsOfView.PointOfView;", 2

sItemText = GetTextFromItemData(cboPublication, cboPOV)

' clsTFSADO.FillComboBox cboPOV1, "SELECT
PointsOfView.ID, PointsOfView.PointOfView FROM
PointsOfView ORDER BY PointsOfView.PointOfView;", 2

' sItemText = GetTextFromItemData(cboPublication,
cboPOV1)

txtPermission.Text = 6


POVTopicIssuer = False

clsTFSADO.FillComboBox cboDateType, "SELECT DateType.ID,
DateType.DateType FROM DateType ORDER BY
DateType.DateType;", 2

cboTopicIssuer.ListIndex = 7
cboPublication.ListIndex = 2
cboPOV.ListIndex = 12
cboDateType.ListIndex = 6
End Sub


Private Sub cmdSaveLOG_Click()
If cboTopicIssuer.ListIndex = -1 Then
MsgBox "No Topic Issuer selected."
CboTopicIssuer.SetFocus
Exit Sub
ElseIf cboPublication.ListIndex = -1 Then
MsgBox "No Publisher selected."
CboPublication.SetFocus
Exit Sub
ElseIf cboPOV.ListIndex = -1 Then
MsgBox "No Point of View selected."
CboPOV.SetFocus
Exit Sub
ElseIf txtPermission.Text <> "6" Then txtPermission = "6"
Exit Sub
ElseIf cboDateType.ListIndex = -1 Then
MsgBox "No Date Type is selected."
CboDateType.SetFocus
Exit Sub
ElseIf Not IsDate(mskDate.Text) Then
MsgBox "The date box does not contain a date."
MskDate.SetFocus
Exit Sub
ElseIf txtTopicText.Text = "" Then
MsgBox "There is no topic text."
CmdOpenFile.SetFocus
Exit Sub

End If
Set gForm = Me
' gsTopicText = txtTopicText.Text
txtTopicText.Locked = True
txtTopicText.BackColor = &HE0E0E0
txtTopicText1.Text = gsTopicText
txtTopicText1.Locked = True
txtTopicText2.Text = gsTopicText
txtTopicText2.Locked = True
UpDateTopic
cmdSaveLOG.Enabled = False
gID = Clng(txtID.Text)



End Sub

In ClsADO



Public Sub FillLBox(lbox As ListBox, iState As Integer)
Dim s As String

Select Case iState

Case 0, 3
While Not cboRS.EOF
s = Trim(cboRS.Fields(1))
lbox.AddItem s lbox.ItemData(lbox.NewIndex) = cboRS.Fields
(0) cboRS.MoveNext
Wend

Case 1
While Not cboRS.EOF
s = Trim(cboRS.Fields(1))
If Len(Trim(cboRS.Fields(2))) = 0 Then
Else s = s & ", " & Trim(cboRS.Fields(2))
End If
lbox.AddItem s
lbox.ItemData(lbox.NewIndex) = cboRS.Fields(0)
cboRS.MoveNext
Wend

Case Else

End Select

End Sub

In modDataChroreography

Public Function UpDateTopic() As Boolean
On Error GoTo Error1
Dim sConn As String
Dim TopicRS As Recordset
'sConn = ConnString
= "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= " &
App.Path & "\hasbarasample.mdb;"

UpDateTopic = False
Set TopicRS = New Recordset
TopicRS.Open "Topics", gsConnString, adOpenDynamic,
adLockOptimistic TopicRS.AddNew
TopicRS("ParentID") = gForm.txtParentID.Text
TopicRS("Title") = gForm.txtTopicTitle.Text TopicRS
("Text") = gForm.txtTopicText.Text
TopicRS("Issuer") = GetItem(gForm.cboTopicIssuer)
TopicRS("Length") = Len(gForm.txtTopicText.Text)
TopicRS("PointOfView") = GetItem(gForm.cboPOV)
TopicRS("PermissionID") = 6
TopicRS("Publisher") = GetItem(gForm.cboPublication)
TopicRS.Update
TopicRS.MoveLast
gForm.txtID.Text = Cstr(TopicRS.Fields(0))
UpDateTopic = True
TopicRS.Close
Set TopicRS = Nothing

Exit Function

Error1: Select Case Err.Number

Case -2147217887, 379 'MsgBox Cstr(TopicRS.Fields(0))
Exit Function

Case Else Exit Function

End Select

End Function

thank you very much.

dennisty
 
I suggest you to directly re-write the code by using ADO.NET, instead of
following the legal ADO code.

Sincerely,

Kevin
Microsoft Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! - www.microsoft.com/security

--------------------
| Content-Class: urn:content-classes:message
| From: "dennist" <[email protected]>
| Sender: "dennist" <[email protected]>
| Subject: migrating subs and procedures to classes and modules
| Date: Sat, 28 Jun 2003 22:51:35 -0700
| Lines: 202
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcM+An/W0u3d+4BYTcypidclzstrNg==
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:54519
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| please excuse my last post on this which was improperly
| formatted due to a utility(text cleaner) that I had
| active.
|
| My problem is that I read ado.net step by step, including
| working out all the examples.
|
| In the end, I still can't create generic procedures in
| classes and modules.
|
| I'm going to give you part of an example from vb 6, and
| ask if you can show me how to do such things in ado.net
|
| Private Sub Form_Load()
|
| 'InitcboQualifier
| 'Set clsTFSADO = New clsADO
| Dim lPrntID As Long
| Dim sItemText As String
| lPrntID = clsTFSADO.ParntID
|
| Me.Save0 = False
| txtTopicTitle.Text = ""
| mskDate = Date
| cmdSaveLOG.Enabled = True
| ComboBoxConnection
| 'SetcboQualifier "POV", "PermissionID"
|
| clsTFSADO.FillComboBox cboTopicIssuer, "SELECT
| TopicIssuers.* FROM TopicIssuers ORDER BY
| TopicIssuers.Issuer;", 2
|
| clsTFSADO.FillComboBox cboPublication, "SELECT
| Publications.ID, Publications.Publication FROM
| Publications ORDER BY Publications.Publication;", 2
|
| sItemText = GetItemText(cboTopicIssuer, cboPublication)
|
| ' clsTFSADO.FillListBox lstAuthors, "SELECT Authors.ID,
| Authors.[Last Name], Authors.[First Name] AS Name FROM
| Authors ORDER BY Authors.[Last Name], Authors.[First
| Name];", 1
|
| clsTFSADO.FillListBox lstAuthors, "SELECT Authors.ID,
| Authors.[Last Name], Authors.[First Name] FROM Authors
| ORDER BY Authors.[Last Name], Authors.[First Name];", 1
|
| sItemText = clsTFSADO.GetLItemText(cboPublication,
| lstAuthors)
|
| clsTFSADO.FillComboBox cboPOV, "SELECT PointsOfView.ID, "
| & "PointsOfView.PointOfView FROM PointsOfView ORDER BY
| PointsOfView.PointOfView;", 2
|
| sItemText = GetTextFromItemData(cboPublication, cboPOV)
|
| ' clsTFSADO.FillComboBox cboPOV1, "SELECT
| PointsOfView.ID, PointsOfView.PointOfView FROM
| PointsOfView ORDER BY PointsOfView.PointOfView;", 2
|
| ' sItemText = GetTextFromItemData(cboPublication,
| cboPOV1)
|
| txtPermission.Text = 6
|
|
| POVTopicIssuer = False
|
| clsTFSADO.FillComboBox cboDateType, "SELECT DateType.ID,
| DateType.DateType FROM DateType ORDER BY
| DateType.DateType;", 2
|
| cboTopicIssuer.ListIndex = 7
| cboPublication.ListIndex = 2
| cboPOV.ListIndex = 12
| cboDateType.ListIndex = 6
| End Sub
|
|
| Private Sub cmdSaveLOG_Click()
| If cboTopicIssuer.ListIndex = -1 Then
| MsgBox "No Topic Issuer selected."
| CboTopicIssuer.SetFocus
| Exit Sub
| ElseIf cboPublication.ListIndex = -1 Then
| MsgBox "No Publisher selected."
| CboPublication.SetFocus
| Exit Sub
| ElseIf cboPOV.ListIndex = -1 Then
| MsgBox "No Point of View selected."
| CboPOV.SetFocus
| Exit Sub
| ElseIf txtPermission.Text <> "6" Then txtPermission = "6"
| Exit Sub
| ElseIf cboDateType.ListIndex = -1 Then
| MsgBox "No Date Type is selected."
| CboDateType.SetFocus

| Exit Sub
| ElseIf Not IsDate(mskDate.Text) Then
| MsgBox "The date box does not contain a date."
| MskDate.SetFocus
| Exit Sub
| ElseIf txtTopicText.Text = "" Then
| MsgBox "There is no topic text."
| CmdOpenFile.SetFocus
| Exit Sub
|
| End If
| Set gForm = Me
| ' gsTopicText = txtTopicText.Text
| txtTopicText.Locked = True
| txtTopicText.BackColor = &HE0E0E0
| txtTopicText1.Text = gsTopicText
| txtTopicText1.Locked = True
| txtTopicText2.Text = gsTopicText
| txtTopicText2.Locked = True
| UpDateTopic
| cmdSaveLOG.Enabled = False
| gID = Clng(txtID.Text)
|
|
|
| End Sub
|
| In ClsADO
|
|
|
| Public Sub FillLBox(lbox As ListBox, iState As Integer)
| Dim s As String
|
| Select Case iState
|
| Case 0, 3
| While Not cboRS.EOF
| s = Trim(cboRS.Fields(1))
| lbox.AddItem s lbox.ItemData(lbox.NewIndex) = cboRS.Fields
| (0) cboRS.MoveNext
| Wend
|
| Case 1
| While Not cboRS.EOF
| s = Trim(cboRS.Fields(1))
| If Len(Trim(cboRS.Fields(2))) = 0 Then
| Else s = s & ", " & Trim(cboRS.Fields(2))
| End If
| lbox.AddItem s
| lbox.ItemData(lbox.NewIndex) = cboRS.Fields(0)
| cboRS.MoveNext
| Wend
|
| Case Else
|
| End Select
|
| End Sub
|
| In modDataChroreography
|
| Public Function UpDateTopic() As Boolean
| On Error GoTo Error1
| Dim sConn As String
| Dim TopicRS As Recordset
| 'sConn = ConnString
| = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= " &
| App.Path & "\hasbarasample.mdb;"
|
| UpDateTopic = False
| Set TopicRS = New Recordset
| TopicRS.Open "Topics", gsConnString, adOpenDynamic,
| adLockOptimistic TopicRS.AddNew
| TopicRS("ParentID") = gForm.txtParentID.Text
| TopicRS("Title") = gForm.txtTopicTitle.Text TopicRS
| ("Text") = gForm.txtTopicText.Text
| TopicRS("Issuer") = GetItem(gForm.cboTopicIssuer)
| TopicRS("Length") = Len(gForm.txtTopicText.Text)
| TopicRS("PointOfView") = GetItem(gForm.cboPOV)
| TopicRS("PermissionID") = 6
| TopicRS("Publisher") = GetItem(gForm.cboPublication)
| TopicRS.Update
| TopicRS.MoveLast
| gForm.txtID.Text = Cstr(TopicRS.Fields(0))
| UpDateTopic = True
| TopicRS.Close
| Set TopicRS = Nothing
|
| Exit Function
|
| Error1: Select Case Err.Number
|
| Case -2147217887, 379 'MsgBox Cstr(TopicRS.Fields(0))
| Exit Function
|
| Case Else Exit Function
|
| End Select
|
| End Function
|
| thank you very much.
|
| dennisty
|
 
Please refer to the following sample code:

==================
Public Shared Sub Test()
Dim nwindConn As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data
Source=C:\northwind2000.mdb;")
' Use the DataAdapter to fill and update the DataSet.
Dim catDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT
CategoryID, CategoryName FROM Categories ORDER BY CategoryID", nwindConn)

nwindConn.Open()

' Fill the DataSet.
Dim catDS As DataSet = New DataSet()
catDA.Fill(catDS, "Categories")

Dim ListBox1 As Windows.Forms.ListBox

'add more lines of codes based on your needs
'<......>
ListBox1.DataSource = catDS

nwindConn.Close()
End Sub
==================

For more information, please refer to MSDN directly.



Sincerely,

Kevin
Microsoft Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! - www.microsoft.com/security

--------------------
| Content-Class: urn:content-classes:message
| From: "dennist" <[email protected]>
| Sender: "dennist" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: migrating subs and procedures to classes and modules
| Date: Mon, 30 Jun 2003 05:52:17 -0700
| Lines: 25
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcM/BnAcKRXUIROzQA29yonWNh2aWw==
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa09.phx.gbl
| Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.adonet:9536
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Kevin,
|
| That's my point. How do you do such a thing in ADO.NET?
| Give me the simplest example of filling a listbox on a
| form with a call to a procedure in a class? One example
| will take me a long ways.
|
| Thank you sir.
|
| dennist
|
| >-----Original Message-----
| >I suggest you to directly re-write the code by using
| ADO.NET, instead of
| >following the legal ADO code.
| >
| >Sincerely,
| >
| >Kevin
| >Microsoft Support
| >
| >This posting is provided "AS IS" with no warranties, and
| confers no rights.
| >Get Secure! - www.microsoft.com/security
|
|
 
Back
Top