Hi Rich... I should have been a little more specific for sure... I just want
to be sure I am on teh right track - that is all...
Yes, the DB I am referring to is a back end SQL Server 2000 database. I
call SQL stored procedures (not embedded SQL) from my vb.net 2005
application to access and load data to/from these tables.
Basically I am trying to develop a business class that encompasses these two
tables. I am very new to OO design so pls bear with me. I have a parent
table and a related child table in a one-many relationship. When I
instantiate the business object, depending on parameters supplied in the
"new()" clause, I beleive I will want to call a method(s) on that object
that will then go out and get me the related rows from the child table, and
load them into my collection so I can then display the collection items in a
listview control etc...
Now, I could create multiple business objects but that does not make
sense -- that is typically where the data objects will come in - as I would
have one data object for each table. In my business object I want to
represent just this one "thing" (object) which is a "Post". Since one single
"Post" can have multiple associated "Details", I think (and hope) I am on
the right track by designing the business object so that I can retrieve the
details using say a "GetPostDetails" method. This method would then fill the
collection property on the Post object. Once filled, I can then do whatever
I want with the collection - display it, print it, etc... etc...
Does this make sense? Do you think I am on the right track?
Thanks, Brad
> Hi Brad,
>
[quoted text clipped - 14 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Rich P - 07 Mar 2008 21:02 GMT
I think I am following you now, and is pretty much what I thought you
were looking for.
Well, if you are new to OO design, not to worry. The days of having to
create little classes for stuff sort of came and went (at least for
VB2005) for data storing/displaying. I create a custom class for stuff
like printing. As for collection objects, I haven't used one for a few
years now. I store data in datasets/datatables which can be available
as much as you want - depending on how much scope you give your dataset.
Ex:
----------------------------------------------
Imports System
Imports System.Data.SqlClient
Public Class Form1
Dim da as SqlDataAdapter, ds As DataSet
Dim conn as SqlConnection
Private Sub Fomr1_Load(...)Handles...
conn = New SqlConnection
conn..ConnectionString = "Data Source=yourSvr;Initial
Catalog=yourDB;Integrated Security=True"
ds = New Dataset
da = New SqlDataAdapter
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandType=CommandType.StoredProcedure
da.SelectCommand.CommandText = "yourSP"
da.Fill(ds,"tblSteve") '--tblSteve gets created on the fly
'--now populate a datagridview control on your form
datagridview1.Datasource = ds.Tables("tblSteve")
End Sub
----------------------------------------------
In this sample I made the dataset at the Form level. So
ds.Tables("tblSteve") will be alive as long as Form1 is alive. And
tblSteve will contain whatever rows/columns your SP contains/returns.
And these can be automatically displayed in a datagridview control (much
easier to deal with and way more flexible than a Listview control).
Well, this is my suggestion.
HTH
Rich
Brad Pears - 10 Mar 2008 18:54 GMT
Great... Thanks for your help... I have not used a datagridview control at
all... Do you have some sample code you could forward that would populate a
datagridview control based on that sample you provided? At this point I am
not going to be allowing the user to add/delete/update rows directly from
the control - it would be for viewing only - but that may change once I see
it in action...
Thanks, Brad
>I think I am following you now, and is pretty much what I thought you
> were looking for.
[quoted text clipped - 43 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***