Append XML Child Node (Additional problems)

G

Guest

I orginally asked this question on friday, and made some progress, but now I
am getting an error.

What is the type of xmlProductName (check the runtime type in the debugger)?

The debug output is as follows.

'DefaultDomain': Loaded
'c:\winnt\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded.
'Zadig': Loaded 'C:\Documents and Settings\mlubrano\My Documents\Visual
Studio Projects\Zadig\bin\Zadig.exe', Symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.windows.forms\1.0.5000.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c561934e089\system.dll', No
symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\microsoft.visualbasic.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'Zadig.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.
An unhandled exception of type 'System.InvalidCastException' occurred in
Zadig.exe

Additional information: Specified cast is not valid.


Unhandled Exception: System.InvalidCastException: Specified cast is not valid.
at Zadig.Products.AddProduct(XmlNode node) in C:\Documents and
Settings\mlubrano\My Documents\Visual Studio Projects\Zadig\Products.vb:line
239
at Zadig.Products.bttnAdd_Click(Object sender, EventArgs e) in
C:\Documents and Settings\mlubrano\My Documents\Visual Studio
Projects\Zadig\Products.vb:line 223
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Zadig.Zadig.Main() in C:\Documents and Settings\mlubrano\My
Documents\Visual Studio Projects\Zadig\Main.vb:line 3The program '[328]
Zadig.exe' has exited with code 0 (0x0).
 
G

Guest

Here is my complete code.

Dim xmlFile As String = xmlLocation()
Dim xmlDoc As XmlDocument

Private Sub Products_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlDoc = New XmlDocument
xmlDoc.Load(xmlFile)


End Sub

Private Sub bttnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bttnAdd.Click
AddProduct(xmlDoc.ChildNodes(0))
'xmlDoc.Save("..\xmldoc.xml")
End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnClose.Click
xmlDoc.Save("..\xmldoc.xml")
Me.Close()
End Sub

Private Sub AddProduct(ByVal node As XmlNode)
Dim xmlProductName = txtProduct.Text
Dim xmlCompanyName = txtCompany.Text
Dim xmlAddress = txtAddress.Text
Dim xmlCity = txtCity.Text
Dim xmlState = cmboState.Text
Dim xmlZip = txtZip.Text
node.AppendChild(xmlProductName)
node.AppendChild(xmlCompanyName)
node.AppendChild(xmlAddress)
node.AppendChild(xmlCity)
node.AppendChild(xmlState)
node.AppendChild(xmlZip)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top