CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2003
    Location
    The Netherlands
    Posts
    40

    is this the way to program in classes? or ......

    I am not used to programming win classes, yes I am a newbie :-x in classes
    (windows app, SQL database, VB.studio net v2003)


    I used the following code to get a connection string wich is located in
    an XML-file.
    I cannot do this in a form_open_event because the classes are triggered
    before any action takas place in opening/activating the form, wich results in error,
    because there is no connection string.

    The code puts the connection string to a modal declared string (m_connString),
    in the class.


    SO, I put the code in the class, right below the my base new.....blabla


    IS this the right way to do, or is there a wiser method to get data into
    a class?
    *****************************************************
    Here is de coding:
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Option Explicit On
    Imports System.Data.SqlClient
    Imports System.Xml.Serialization
    Imports System.IO
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Public Class DataServiceSQL
    Private m_connString As String
    Private m_con As SqlConnection
    Friend WithEvents m_da As New SqlDataAdapter

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Public Sub New()
    Dim p As New XML
    Dim x As New XmlSerializer(p.GetType)

    Dim objStreamReader As New StreamReader("D:\Documents and Settings\Administrator\Mijn documenten\Visual Studio Projects\WindowsApplication49\DMS.xml")
    Dim p2 As New XML
    p2 = x.Deserialize(objStreamReader)
    objStreamReader.Close()

    m_connString = p2.strMyConn
    m_con = New SqlConnection(m_connString)
    End Sub
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Public Property GetConnString() As String
    Get
    Return m_connString
    End Get
    Set(ByVal Value As String)
    m_connString = Value

    End Set

    ****************************************************
    Have a day,

    reinier

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    Keep in mind that even though classes have guidelines, there is a good deal of personal preference involved when designing them. So there may be more then one way to do the same thing, and there usually is.

    Before I make any suggestions.. is that all of the code for the class?
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Jul 2003
    Location
    The Netherlands
    Posts
    40

    is this the way to program in classes? or ......

    HI Craig,

    Of course we are all free in implementing our prgram codes,
    but because this (class programming) is new to me, there
    might be a neater more efficiant way of programming.

    There is more in the class, the coding I showed was only
    for retrieving the connection string from a xml file.

    More in this class is for receiving the dataset, receiving
    update,delete and insert commands for the dataadapter.
    (nothing special)

    regards,
    reinier

  4. #4
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    With out seeing all of the code, it's hard to comment on whether this is a good idea or not. The one thing that I might suggest is to turn it into a shared member class. It appears that you are only going to use this class once, so it would be a good candidate for shared members.

    http://support.microsoft.com/default...308371&SD=MSDN
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  5. #5
    Join Date
    Jul 2003
    Location
    The Netherlands
    Posts
    40

    is this the way to program in classes? or ......

    Thanks Craig!

    I did look onto it very quikly,
    I looks very promising.

    Do you know by change, if this is a way
    a sending data from a module to a class?

    Regards,
    reinier

  6. #6
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    You can add a parameter to the method in the class.
    Code:
    Public Class1
    
    Public Sub DoSomething( sText as String ) 
     Msgbox(sText)
    End Sub
    
    End Class
    Non-shared way to call that method:

    Dim oMyClass as New Class1
    oMyClass.DoSomething("Hello")

    Shared way to call that method:

    Class1.DoSomething("Hello")
    Last edited by Craig Gemmill; March 10th, 2004 at 01:31 PM.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  7. #7
    Join Date
    Jul 2003
    Location
    The Netherlands
    Posts
    40

    is this the way to program in classes? or ......

    T H A N K S

    reinier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured