Click here to Skip to main content
15,918,109 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: how to set parent window Pin
Dave Kreskowiak8-Apr-06 2:52
mveDave Kreskowiak8-Apr-06 2:52 
QuestionReuse DB connection Pin
alwinSCH6-Apr-06 1:09
alwinSCH6-Apr-06 1:09 
AnswerRe: Reuse DB connection Pin
ToddHileHoffer6-Apr-06 2:24
ToddHileHoffer6-Apr-06 2:24 
GeneralRe: Reuse DB connection Pin
alwinSCH6-Apr-06 2:51
alwinSCH6-Apr-06 2:51 
GeneralRe: Reuse DB connection Pin
Dave Kreskowiak6-Apr-06 10:37
mveDave Kreskowiak6-Apr-06 10:37 
QuestionHelp with Dynamic Casting Pin
hertz_j6-Apr-06 0:40
hertz_j6-Apr-06 0:40 
AnswerRe: Help with Dynamic Casting Pin
Dave Kreskowiak6-Apr-06 9:36
mveDave Kreskowiak6-Apr-06 9:36 
GeneralRe: Help with Dynamic Casting Pin
hertz_j6-Apr-06 23:15
hertz_j6-Apr-06 23:15 
Hi Dave,

Thanks for the response. My question was probably not very clear. What I want to do is not cast using the xml innertext type but the obj(name) type.

I know this looks wired and I guess it is. What I’m doing (and I know when it comes to performance it is just wrong) is to map from the xml node to a property in the object using the name of the properties. Now it becomes even worse, I use reflection to get the properties names and I invoke them instead of setting the normal way. I know this is extremely inefficient in performance terms, but it is very dynamic and I like the simplicity of the code.

So what happens is:
1) An XML node is read
2) Loop over the child nodes
3) Set the object (Query) properties to the node value with the same name. (Dynamically casting to the property’s type)

Here is the function that does the trick.
<br />
'Builds a query from a xml node<br />
Private Function BuildQuery(ByRef node As XmlNode) As Query<br />
<br />
  Try<br />
      Dim obj As New Query<br />
<br />
      'Map xmlnodes to properties where the names match<br />
      For Each name As String In obj.Properties<br />
          If Not node.SelectSingleNode(name) Is Nothing Then<br />
<br />
              'Dynamically cast to the type of the property <br />
              Dim code As Integer = CInt(Convert.GetTypeCode(obj(name)))<br />
              obj(name) = Convert.ChangeType(node.SelectSingleNode(name).InnerText, code)<br />
<br />
          End If<br />
      Next<br />
<br />
      Return obj<br />
  Catch ex As Exception<br />
      Throw New ApplicationException("Falied to build Databasequery object", ex)<br />
   End Try<br />
End Function<br />


On a side note I only use this rarely in the code, for reading data into object and moving data from object into file or database. These are expensive operations anyway so the overhead is not that great compared to the actual workload. That is at least the theory, but I need to do some test to check if it is correct.

Thank you very much for your reply.
Johan Hertz
GeneralRe: Help with Dynamic Casting Pin
Dave Kreskowiak7-Apr-06 2:50
mveDave Kreskowiak7-Apr-06 2:50 
GeneralRe: Help with Dynamic Casting Pin
hertz_j9-Apr-06 22:24
hertz_j9-Apr-06 22:24 
Questionmdi child form connection with menu item of main form Pin
Sweet Virgo6-Apr-06 0:39
Sweet Virgo6-Apr-06 0:39 
AnswerRe: mdi child form connection with menu item of main form Pin
Dave Kreskowiak6-Apr-06 9:05
mveDave Kreskowiak6-Apr-06 9:05 
GeneralRe: mdi child form connection with menu item of main form Pin
Sweet Virgo6-Apr-06 18:07
Sweet Virgo6-Apr-06 18:07 
Questionhow to insert data in database(its urgent) Pin
Amit Agarrwal6-Apr-06 0:29
Amit Agarrwal6-Apr-06 0:29 
AnswerRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 1:01
daviiie6-Apr-06 1:01 
GeneralRe: how to insert data in database(its urgent) Pin
Amit Agarrwal6-Apr-06 1:56
Amit Agarrwal6-Apr-06 1:56 
GeneralRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 2:08
daviiie6-Apr-06 2:08 
GeneralRe: how to insert data in database(its urgent) Pin
Amit Agarrwal6-Apr-06 2:23
Amit Agarrwal6-Apr-06 2:23 
GeneralRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 2:29
daviiie6-Apr-06 2:29 
GeneralRe: how to insert data in database(its urgent) Pin
daviiie6-Apr-06 2:35
daviiie6-Apr-06 2:35 
AnswerRe: how to insert data in database(its urgent) Pin
Guffa6-Apr-06 2:59
Guffa6-Apr-06 2:59 
QuestionSimple Question....background..... Pin
daviiie5-Apr-06 23:24
daviiie5-Apr-06 23:24 
AnswerRe: Simple Question....background..... Pin
Chatura Dilan6-Apr-06 0:00
Chatura Dilan6-Apr-06 0:00 
GeneralRe: Simple Question....background..... Pin
daviiie6-Apr-06 0:08
daviiie6-Apr-06 0:08 
GeneralRe: Simple Question....background..... Pin
Chatura Dilan6-Apr-06 2:09
Chatura Dilan6-Apr-06 2:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.