I think I would approach this in a different way. You say that your
Contact class is serializable because you want to store it in a
database. Do you mean you will be serializing and storing each object
of this class in a database table? This is not standard practice for
database apps.
Here's a rough sketch-out of what I would do:
Step 1: In the database
- Create a database table, tblContact.
- Give it a varchar column called Name.
Step 2: the server-side code
- Create a Class Library project that includes two public methods:
GetContacts
UpdateContacts
- Your GetContacts method will receive a dataset object ByRef.
It will fill this dataset with the contents of your tblContact
table.
- Your UpdateContacts method will also receive a dataset object
byref,
and will use it to update tblContacts. This will be done via
the
Update method of the DataAdapter.
- configure remoting for this app to make it available via remoting
Step 3: the client-side code
- create either a Windows app or a Web App
- configure remoting in this app to access the above server-side
DLL
via remoting (either HTTP or TCP)
- put a datagrid on your form
- call your GetContacts method to get a dataset filled with
contacts
- bind this dataset to your grid
- allow the user to add, update, delete contacts in the grid
- Give the user a Save button on the form. When they click Save,
call the
UpdateContacts method and pass the updated dataset.
This is a high-level overview of how the DataGrid, DataSet, and
Remoting come together to make a distributed app. You can have a
single server-side component that is accessed from multiple clients,
including Win Form, Web Form, or API-style access (i.e. from another
application). And you don't have to use remoting for this; you can do
basically the same thing using a web service.
Hope this helps.
John
[quoted text, click to view] "Russ" <russ@UKS.com> wrote in message news:<eh#CdqcYDHA.1580@tk2msftngp13.phx.gbl>...
> Hi,
>
> I'm using VB.net 1.1 to build a Web based server and a Windows based client.
> Having read through two books and various articles I'm beggining to wonder
> if this is simply beyond my mental capacity. Sorry this goes on a bit, but
> any help would be greatly appreciated.
>
> I have a 'contact' object which is serializable because it is serialised to
> a database.
>
> <Serializable()> Public Class Contact
> Private I_Name As String
>
> Public Property Name()
> Get
> Return I_Name
> End Get
> Set(ByVal Value)
> I_Name = Value
> End Set
> End Property
> End Class
>
> I have also defined an object called AllContacts to hold these objects
> called which I have inherited from MarshallbyrefObject. This has one
> field, a public arraylist to hold the 'contact' objects.
>
> Public Class AllContacts
> Inherits MarshalByRefObject
> Public Contacts As ArrayList
> End Class
>
> I need both the web site and one or more windows based clients to be able to
> add new contacts and edit existing ones to this. For the website, I have
> defined everything at application level in a module, so the objects are
> available to all aspx pages. For the purposes of this test, Session Start
> calls the Initailize sub which adds 2 contacts and then publishes the ACs
> object.
>
> Module MainModule
> Public ACs As New AllContacts
> Public Ref As ObjRef
>
> Sub Initailize()
> add2cs()
> SetChannel()
> End Sub
>
> Sub SetChannel()
> Dim Channel As Http.HttpChannel
> Channel = New Http.HttpChannel
> ChannelServices.RegisterChannel(Channel)
> Ref = RemotingServices.Marshal(ACs, "all.rem")
> End Sub
>
> Sub add2cs()
> Dim C As Contact
> C = New Contact
> C.Name = "bob"
> ACs.Contacts.Add(C)
> C = New Contact
> C.Name = "john"
> ACs.Contacts.Add(C)
> End Sub
> End Module
>
> Webform1.aspx then displays ACs.Contacts.count which when the site first
> starts has a value of 2.
>
> My client code also references the classes defined above looks like this.
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> Dim AllCs As AllContacts
> Dim Cs As ArrayList
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Connect()
> End Sub
>
> Sub Connect()
> AllCs = Activator.GetObject(GetType(AllContacts),
> "http://work/remserver/all.rem")
> Cs = AllCs.Contacts
> ' At this point Cs.length = 2 - great!
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim C As New Contact
> C.Name = "bill"
> AllCs.Contacts.Add(C)
> Cs = AllCs.Contacts
> ' Cs.length is still 2 - not great
> End Sub
> End Class
>
> When I run this, Cs.length = 2 the line after Activator.getobject which is
> what I would expect, but clicking Button1 has no effect, I would now have
> expected Cs.length to be 3, but it remains at 2, and I was kinda hoping that
> when I refreshed Webform1.aspx on the site, the count would also be 3.
>
> I know I'm obviously missing something fairly fundamental here, but I'm
> clueless as to what it is.
>
> Help? Please?
>
> Thanks,