|
Hi ,
thanks for your help...
there was a slight typo error in the xml structure... it should have reflected as below
<Orders>
<OrderHeader>
<CustomerPoNumber>TEST1</CustomerPoNumber>
<ErrorMessages>
<ErrorDescription>Invalid Po 'TEST1'</ErrorDescription>
</ErrorMessages>
</OrderHeader>
<OrderDetails>
<Stock>
<Line>0001</Line>
<ErrorMessages>
<ErrorDescription>'EAE' invalid</ErrorDescription>
<ErrorDescription>'EAS' invalid</ErrorDescription>
</ErrorMessages>
</Stock>
<Stock>
<Line>0002</Line>
<ErrorMessages>
<ErrorDescription>Price invalid</ErrorDescription>
</ErrorMessages>
</Stock>
</OrderDetails>
</Orders>
i have managed to come up with a solution that works for now even though it's very messy...
have a look...
Private Function GetErrors(ByVal XML As String, ByVal Path As String) As DataTable
Try
Dim DOC As New Xml.XmlDocument
DOC.LoadXml(XML)
Dim ndParent As XmlNodeList
'Path = //Orders
ndParent = DOC.SelectNodes(Path)
Dim nd As XmlNode
Dim ndC1 As XmlNode
Dim ndC2 As XmlNodeList
Dim nd1 As XmlNode
Dim nd2 As XmlNode
Dim out As String = ""
Dim dt As New DataTable
dt.Columns.Add("PoNum")
dt.Columns.Add("So")
dt.Columns.Add("Line")
dt.Columns.Add("Error")
dt.Columns.Add("ErrHdr")
Dim row As DataRow
Dim PoNum As String = ""
Dim Line As Integer = 0
Dim errmsg As String = ""
Dim errhdr As String = ""
For Each nd In ndParent
'below reads the first level i.e. order header + order details
For Each ndC1 In nd.ChildNodes
Select Case ndC1.Name.Trim
Case "OrderHeader"
'get the childnodes of OrderHeader
'xml result should search for FieldName i.e. "CustomerPoNumber"
ndC2 = ndC1.ChildNodes
PoNum = XmlResult(ndC2, "CustomerPoNumber")
errhdr = XmlResult(ndC2, "ErrorMessages")
'out &= XmlResult(ndC2, "ErrorMessages")
Case "OrderDetails"
'ndC2 = ndC1.ChildNodes
For Each nd1 In ndC1
Line = Me.XmlResult(nd1.ChildNodes, "Line")
For Each nd2 In nd1.ChildNodes 'stockline
If nd2.Name = "ErrorMessages" Then
errmsg = Me.XmlResult(nd2.ChildNodes, "ErrorDescription") & " ; "
' out &= Me.XmlResult(nd2.ChildNodes, "ErrorDescription")
End If
Application.DoEvents()
Next
row = dt.NewRow
row("PoNum") = PoNum
row("Line") = Line
row("Error") = errmsg
row("ErrHdr") = errhdr
dt.Rows.Add(row)
Application.DoEvents()
Next
End Select
Next
Next
Return dt
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Function XmlResult(ByVal node As XmlNodeList, ByVal Column As String) As String
Try
Dim nd As XmlNode
Dim nd2 As XmlNode
Dim strOut As String = ""
For Each nd In node
If nd.Name = Column Then
For Each nd2 In nd.ChildNodes
strOut = strOut & nd2.InnerText & vbCrLf
Application.DoEvents()
Next
End If
Next
nd = Nothing
Return strOut
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Function
thanks once again for your help....
appreciate it!
|
|
|
|
|
I have optimized the code a bit more, kindly check it out:
Public Function XmlToDataTable(ByVal path As String) As DataTable
Dim dt As New DataTable
Dim doc As New XmlDocument()
Dim PoNum As String = String.Empty
Dim Header As String = String.Empty
doc.Load(path)
dt.Columns.Add("PoNum")
dt.Columns.Add("Header")
dt.Columns.Add("Line")
dt.Columns.Add("Error")
Dim cnt As Integer = doc.SelectNodes("Orders/OrderHeader").Count
For k As Integer = 0 To cnt - 1
Dim node As XmlNode = doc.SelectNodes("Orders/OrderHeader").Item(k)
PoNum = node.Item("CustomerPoNumber").InnerText
Header = node.Item("ErrorMessages").InnerText
Dim n As Integer = doc.SelectNodes("Orders/OrderDetails").Count
For m As Integer = 0 To n - 1
Dim element As XmlNode = doc.SelectNodes("Orders/OrderDetails").Item(m)
Dim obj(3) As Object
obj(0) = PoNum : obj(1) = Header
For Each stocks As XmlNode In element.ChildNodes
Dim line As String = stocks.Item("Line").InnerText
Dim description As String = stocks.Item("ErrorMessages").InnerXml.Replace("</ErrorDescription><ErrorDescription>", " & ").Replace("<ErrorDescription>", "").Replace("</ErrorDescription>", "")
obj(2) = line : obj(3) = description
dt.Rows.Add(obj)
Next
Next
Next
Return dt
End Function
|
|
|
|
|
Hi
thanks, will try this out nd get back to you.
thanks for your help...
|
|
|
|
|
If you are reading the XML from file have a look at Dataset.ReadXML(filename)[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
I have written a code to change the back color of a label twice during execution to give it an animation effect. The idea says that :
when the button is pressed change the color from black to red.
Then a null loop is placed to create some delay and then the color changes back to black.
<pre lang="vb">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
box.BackColor = Color.Red
For delay As Double = 0 To 900000000 Step 1
Next
box.BackColor = Color.Black
End Sub</pre>
But its not performing as desired. The label doesnt become red and i doubt the program is executing the delay first. Any idea whats the issue?
|
|
|
|
|
|
You're getting downvoted because you cannot touch a UI control from any other thread other than the thread that created it (the startup thread.)
|
|
|
|
|
Thanks, very elementary mistake. Note to self, think before posting. I have corrected the answer below(first one was removed).
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Your code is running on the startup thread, also called UI thread. If the thread is blocked there is no way it can process the Windows PAINT messages that tell the controls to repaint themselves. This is why your label doesn't change color until your button Click method is done executing.
You have to move your work to a background thread. The problem is you cannot make changes to a control, such as changing the background color, from anything other that the UI thread. Once your background thead "work" is done the background thread can notify the foreground thread to change the label color as appropriate.
Read this article[^] for a discussion and alternate methods of modifying controls from background threads.
|
|
|
|
|
|
You will need to change the colour back using a separate thread. Something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newThread As New Threading.Thread(New Threading.ThreadStart(AddressOf ChangeBGColour))
newThread.Start()
Label1.BackColor = Color.Red
End Sub
Delegate Sub changeLabelColour()
Private Sub ChangeBGColour()
Threading.Thread.Sleep(3000)
If Me.Label1.InvokeRequired Then
Dim c As New changeLabelColour(AddressOf ChangeBGColour)
Me.Invoke(c)
Else
Label1.BackColor = Color.Yellow
End If
End Sub
I added proper UI thread access . My apologies for the basic thread error.
Hope this helps
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
That's an excellent answer.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Cheers.
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Today I wrote a file compressor in Visual Basic, which stores its data in PNG images. It's called Squash.
Squash works by throttling the bytes of a file into a PNG image, storing 3 bytes per pixel in the Red, Green & Blue components. It works in a similar way to a ZIP file, but there is no extraction and apart from the extension (e.g. Document.docx.squash), the format is data/file type agnostic. Files with consistent byte patterns or 'blank' regions compress very well with Squash because these form solid or consistent areas in the graphic.
Here are the results - Results Graphic[^]
Squish is a free, single-executable file compressor. Just drag files on to Squash and find a .squash file in the same folder.
Squash is great for instant messaging, and can greatly improve transfer times. If your contacts have Squash too, they can just open the received file and it gets decompressed on the fly.
Just drop the EXE anywhere on your computer and start saving space - and time.
Project Page on my Site[^]
Download (EXE, 330k)
Source (ZIP, 150k)
If you go to the 'Project page on my Site' link, you can find the source and big explanation of how it works. The explanation is targeted towards beginners.
|
|
|
|
|
Hi all...
I am going to make a multi-user database application in VB.NET (VS 2008).
I have made several db program using different databases and made some client-server based chat programs. But I never worked on multi-user db program.
I wanna know that which database should I use as back-end. Application will be accessible by 3-5 users.
I also wanna know that from where to start to build multi-user program.
Suggest me.
Thanks.
Gagan
|
|
|
|
|
Assuming you're not storing ridiculously massive amounts of data, SQL Server Express would be a reasonable choice. Actually, pretty much anything but Access would be reasonable - there are way too many WTF's created by trying to make a multi-user Access system!
|
|
|
|
|
Personally, I use MySQL as the database and I connect my client application using WCF services.
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Go with Sql Server Express, and get the Sql Server Management Studio to go with it. They're free, and should work for you. I think the db limit is now up to 10 gigs
|
|
|
|
|
Hi, I am looking into using Codility.com for screening newhires, anybody heard about it or better used it for anything serious?
Thanks
Thanks for help.
MadMax2011
|
|
|
|
|
Why did you choose the VB section for this post?
Would one of the other section not have been more applicable e.g. 'Running a business' or 'Work Issues'
|
|
|
|
|
I opened the demo-test, and closed it as soon as it finished loading. The problem-statement was an academic description, not a practical one - and it seems to measures success, not efficiency.
Must have been a nice and cool exercise to write, but it's not a tool I'll be using.
Bastard Programmer from Hell
|
|
|
|
|
Hello !
i have a sql server 2008r2 database ( stu) with a table (st) with these columns :
stID - identity (int autoincrement value)
name - char(10)
com - char(20)
i have a project in vb.net 2010 , and i have generated entity framework model with the database.
I have a form with a listbox and 2 textbox , and 2 buttons Addrecord and Saverecord.
The listbox is bound with an object from entity (stBindingSource) and displayMember: name , Valuememeber : stID. The form is also binded with stbindingsource. ( textbox1:name , Textbox2: com)
I want to add new record.The code is :
……-----------------------------------
Dim stu As stuEntities
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
stu= New stuEntities
stBindingSource.DataSource = stu.sts
End Sub
---------------------------------------------
Private Sub Addrecord_Click(sender As System.Object, e As System.EventArgs) Handles Addrecord.Click
stBindingSource.AddNew()
End Sub
-------------------------------------------------
Private Sub Saverecord_Click(sender As System.Object, e As System.EventArgs) Handles Saverecord.Click
stBindingSource.EndEdit
stu.SaveChanges(System.Data.Objects.SaveOptions.None)
End Sub
So ,first i click to "Addrecord" , and after i fill the 2 textbox , i click Saverecord.
The first record is saved with no problem.If a add another record , the record is saved , but when I open the table on database , the first record is saved 2 times , the second record is saved 1 time.
I try to add 3,4… records and everytime the last record is saved 1 time the others are all duplicated
If I call stu.SaveChanges() , with no parametres , I can’t add any records because I get an error :
The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
Please help me.
Thank you.
modified on Monday, August 29, 2011 9:41 PM
|
|
|
|
|
Hello!
I've got a piece of code where I need to parse a XML-file and store the data in a DataTable do modify and use the data from the file. I'm a bit stuck on the SelectNodes method.
If I have a XML file that looks like this:
="1.0"="utf-8"
<MASTER.DATA>
<Envelope>
<MessageId>146413</MessageId>
<MessageType>DataExport</MessageType>
<Version>1.0.0</Version>
<Sender>x4</Sender>
<Created>2011-08-23T00:01:45.2367404+02:00</Created>
</Envelope>
</MASTER.DATA>
The following code works like a charm:
Dim xd As XmlDocument
Dim xnl As XmlNodeList
xd = New XmlDocument()
xd.Load(fileName)
xnl = xd.SelectNodes("/MASTER.DATA/Envelope")
BUT! The file doesn't exactly look like that. The MASTER.DATA actually looks like this:
<MASTER.DATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nnnn.com/schemas/sys/1.0/integration IntegrationDocumentSchema.xsd" xmlns="http://nnnn.se/schemas/sys/1.0/integration">
And all of a sudden I don't get bupkis with the above mentioned code. What am I doing wrong??
Any help is greatly appreciated.
//Jagg
Wexelblats algorithm:
Pick two: 1. Good, 2. Fast, 3. Cheap
|
|
|
|
|
I'm not sure whether the dot in the name of your rootnode is allowed. I'd go for a name without a dot.
<MASTERDATA ..>
(more stuff)
</MASTERDATA> The query below should work;
xnl = xd.SelectNodes("//MASTERDATA/Envelope") Or, to get a specific piece;
xnl = xd.SelectNodes("//MASTERDATA/Envelope[MessageId='146413']") Hope this helps
Bastard Programmer from Hell
|
|
|
|
|
Hi, thanks for the reply.
However, that didn't work either. It works as soon as I remove all the other definitions (xmlns:xsi, xsi:schemaLocation and xmlns) from the MASTER.DATA (or MASTERDATA) but as soon as they are in the file it goes completely blank. I don't get any errors, I just don't find anything.
Regarding removing the dot (MASTER.DATA) it's probably not possible, this file gets sent automatically from one of our back end systems.
Wexelblats algorithm:
Pick two: 1. Good, 2. Fast, 3. Cheap
|
|
|
|