reinier
Active member
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
End Property
Have a nice day,
reinier
(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
End Property
Have a nice day,
reinier
