|
Perhaps if you told me the error, but .Value should return a string, not a node. That's the point, it REPLACES the call to InnerText, which you can't use, it won't work.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Sorry, I'm pretty new to this and am now a bit confused. In the original code above:
Dim fullpath As String = node.Attributes.GetNamedItem("fullpath").Value
Works and returns a value for "FullPath"
Dim SizeData As String = node.Attributes.GetNamedItem("SizeData").Value
Doesn't work and gives an "System.NullReferenceException" Error when compiled.
When that line is commented out the code returns all expected results.
Am I missing something here as the "fullpath" line in the XML is of the same form as the "SizeData" one.. So why do I get the error???
|
|
|
|
|
You are going about it in a kind of roundabout way (i prefer XPath) but I digress, you were on the correct path with your "subnode" line. Following your method, I just add two lines (your original subnode is the same).
Dim subnode = node.SelectSingleNode("Name")
Dim subnode2 = node.SelectSingleNode("SizeData")
Dim SizeData As String = subnode2.Attributes.GetNamedItem("Size").Value
|
|
|
|
|
Fantastic.. it's working....
here is the final code :
Try
Dim odoc As New System.Xml.XmlDocument
odoc.Load("C:\test\10g_2.xml")
Dim oXmlLog As System.Xml.XmlElement
Dim text As String = ""
For Each oXmlLog In odoc.SelectNodes("Root")
Dim node As System.Xml.XmlElement
For Each node In oXmlLog.SelectNodes("Folder")
Dim fullpath As String = node.Attributes.GetNamedItem("fullpath").Value
'Dim SizeData As String = node.Attributes.GetNamedItem("SizeData").Value
Dim subnode = node.SelectSingleNode("Name")
Dim name As String = subnode.InnerText
Dim subnode2 = node.SelectSingleNode("SizeData")
Dim SizeData As String = subnode2.Attributes.GetNamedItem("Size").Value
Dim Date_ As XmlElement = odoc.DocumentElement
Dim Date_time As XmlNodeList = Date_.ChildNodes
Dim Date__time = (Date_time(0).InnerText)
text &= Date__time & " " & fullpath & " " & name & " " & SizeData & Environment.NewLine
Next
Next
Console.Write(text)
Console.Read()
Catch ex As Exception
Console.Write(ex.ToString())
Console.Read()
End Try
Now I just need to get it to pass this info to SQL..
Thanks again...
|
|
|
|
|
Just because it might be easier for you to work with, take a look at this method. Drag a datagridview onto your form designer and put in the following code, change the table to see your different output. VS is very good at converting between XML and Datasets and vice-versa. If nothing else, the tables will help you visualize the structure of the XML, you can easily see from this sample that size is on a different 'level' than the rest of the data.
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'load xml into a dataset to use here
Dim dS As New DataSet
Dim fS As FileStream
'open the xml file so we can use it to fill the dataset
fS = New FileStream("C:\test\10g_2.xml", FileMode.Open)
'fill the dataset
Try
dS.ReadXml(fS)
Catch ex As Exception
MsgBox(ex)
Finally
fS.Close()
End Try
Me.DataGridView1.DataSource = dS.Tables(2)
End Sub
End Class
|
|
|
|
|
Hello Community,
I have the following query:
SELECT Inventory.Inventory_Id, Inventory.Inventory_description, Inventory.Inventory_stock_count, nz((SELECT Sum(Order.item_qty) AS SumOfitem_qty
FROM [Order]
WHERE Order.From_date<=Date() AND (Order.To_date)>=Date()
AND Order.Item_ID="I" & Inventory.Inventory_Id),0) AS CurrentlyOut, [Inventory_stock_count]-Nz((SELECT Sum(Order.item_qty) AS SumOfitem_qty
FROM [Order]
WHERE Order.From_date<=Date() AND (Order.To_date)>=Date()
AND Order.Item_ID="I" & Inventory.Inventory_Id),0) AS NetHere
FROM Inventory;
This query runs perfectly under data access,
But when i put it under vb.net
my query1 = "SELECT Inventory.Inventory_Id, Inventory.Inventory_description, Inventory.Inventory_stock_count, nz((SELECT Sum(Order.item_qty) AS SumOfitem_qty
FROM [Order]
WHERE Order.From_date<=Date() AND (Order.To_date)>=Date()
AND Order.Item_ID="I" & Inventory.Inventory_Id),0) AS CurrentlyOut, [Inventory_stock_count]-Nz((SELECT Sum(Order.item_qty) AS SumOfitem_qty
FROM [Order]
WHERE Order.From_date<=Date() AND (Order.To_date)>=Date()
AND Order.Item_ID="I" & Inventory.Inventory_Id),0) AS NetHere
FROM Inventory"
cmd.commadtext = myquery1
cmd.executenonquery()
VB.net compiler do not seem to like Nz function that is same as isnull in sql or NVL in oracle & i see this error
Undefined function 'nz' in expression.
it seems that vb.net is not being able to understand the nz function that replace with 0 . nz replaces null values with 0. i really need nz to be present in the query.
what is a way around this?
Best regards.
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
1. You need extra quotes around the I part of ="I" (both places) as this will be terminating your string, I'm suprised it compiled
2. cmd.executenonquery()is not for selects, it does not return a data reader, its for update type statements where there is no recordset returned
3. What nz does I don't know, its not a sql command I've come across, so can't help on that, but the other two may get you somewhere.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Order.Item_ID='I'
Sorry about that, that is the way i wrote it in vb.
you need to understand that when i execute the query without NZ it's fine...
i am taking the cmd.executenonquery in a dataset & i can see the values normaly in a grid but the problem is that the blank values returned when not replaced with 0 are making me a problem with calculations.
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
nz is an old Access/VB function that does not exist in SQL server. what you need is ISNULL()
Sum(ISNULL(Order.item_qty,0))
|
|
|
|
|
this is the query i tested with:
select sum(ISNULL(inventory_id,0)) from inventory
this is the error:
Wrong number of arguments used with function in query expression 'SUM(ISNULL(inventory_id,0)'
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
Sorry, I use SQL Server, I have no idea what the syntax for Oracle is. However you are on the right track, SQL Server has Books On Line which is installed with every client, I imagine Oracle something similar.
|
|
|
|
|
Sorry maybe you misunderstood me prior...
Frontend: vb.net
Backend: MS access 2007
it seems that vb.net does not like ISNULL too...
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
rabih.tawil wrote: it seems that vb.net does not like ISNULL too...
I don't think you understand your own code at all. VB is just passing 'ISNULL' to Access, it has no opinion on it at all. You need to read up on Access SQL, but Access is not that great, I would not be surprised to find it was missing some stuff.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: I don't think you understand your own code at all
Look my friend, this is a 3 month project, i think i understand exactly what i'm doing, just because it has not come accross you before does not mean i don't know what i'm doing...
Christian Graus wrote: VB is just passing 'ISNULL' to Access
OH REALLY? wow great discovery!! now explain to me, why VB wont pass NZ function directly to access???
Christian Graus wrote: it has no opinion on it at all.
I am sorry to tell you my friend, NO you are wrong, the sql query u send will execute depends on the access driver.
Christian Graus wrote: ou need to read up on Access SQL
The query executes successfully in access.. no need to read anything about access.
Christian Graus wrote: but Access is not that great, I would not be surprised to find it was missing some stuff.
Humm, that is your opinion, remember MS access is not a small application made over night for a quick criticism even if one is an mvp. however, the customer wanted MS access so i give him access
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
rabih.tawil wrote: Look my friend, this is a 3 month project, i think i understand exactly what i'm doing, just because it has not come accross you before does not mean i don't know what i'm doing...
ROTFL. OK, perhaps you just meant the opposite of what you said. I apologise.
rabih.tawil wrote: OH REALLY? wow great discovery!! now explain to me, why VB wont pass NZ function directly to access???
Now it seems to me like you have no idea after all. VB IS going to pass your code directly to Access. What else would it do with them ?
rabih.tawil wrote: I am sorry to tell you my friend, NO you are wrong, the sql query u send will execute depends on the access driver.
Wrong. The generic driver will use ODBC ( I think ), but whatever it uses, it will NOT interpret the SQL, it will pass it to the database.
rabih.tawil wrote: Humm, that is your opinion, remember MS access is not a small application made over night for a quick criticism even if one is an mvp.
No, it's a POS that was developed a bit at a time, over time, with no thought to conformance to SQL standards.
rabih.tawil wrote: however, the customer wanted MS access so i give him access
Well, fine. So now you need to learn what the Access SQL dialect is like, and use it accordingly
I did a google, and Access does appear to support ISNULL.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
From here webcheatsheet[^]
In Access, the IsNull function returns a boolean value that indicates whether or not an expression contains no valid data (Null).
The syntax for the IsNull function is:
IsNull ( expression )
In Access, the expression argument can be any numeric or string expression. The IsNull function returns True (-1) if the expression contains the Null value; otherwise, it returns False (0). Null is not the same as a zero-length string, which is often referred to as a null string.
Important: Using the IsNull function is the only way from within Access to determine whether or not an expression contains a null value.
Example
IsNull(null) returns TRUE
IsNull("WebCheatSheet") returns FALSE
IsNull(2006) returns FALSE
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Andy_L_J wrote: IsNull("WebCheatSheet") returns FALSE
IsNull(2006) returns FALSE
LOL - looks like you got the same google hit I did.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
VB.NET has nothing to do with the error. It is not compiling your SQL string. The Jet database engine (Access) is what is throwing the error.
|
|
|
|
|
You need to read the documentation. Isnull returns true or false, depending on if the value is null or not. It takes one arguement, not two. You should RTFM instead of just guessing.
Unfortunately, Nz appears to be the function that you should use in Access in place of Coalesce, which is what you're really trying to do. However, Nz evaluates if something is zero, not null. So, that could be why you had an error in the first place. I don't use access, I found all this out with a tiny bit of googling. What you need is an equivelant to the ? : syntax in C#, which I think is Iif in VB.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: You should RTFM instead of just guessing.
hi Mr genius,
i didn't introduce isnull as an alternative to nz it was Mycroft Holmes, & it doesn't need manuals to understand what it does it looks like it returns Boolean Is??? NULL?? yes NO?? intellisense in vb.net anyway shows you that it is not a big research FYOFK
here is a small SCIENTIFIC DEMONSTRATION video for you to prove you WRONG that ms access is not throwing the exception, the query runs fine in access.
http://www.youtube.com/watch?v=6KhWMcSf_ys
UNLIKE SOME PEOPLE I KEEP MY MOUTH SHUT WHEN I DON'T KNOW ABOUT SOMETHING.
in case you don't believe it:
HERE IS THE SOLUTION DOWNLOAD IT & EXPERIMENT WITH IT YOURSELF, data.accdb is the access & i guess you know how to open a vb.net solution.
http://www.coderisland.com/query_testing.zip
now Please, if your scientific is going to be girl talk do not waist my time,
if your scientific, i challenge you.
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
If this is a copy'n'paste version of your exact code, line for line, then you've got a problem. VB.NET doesn't (until 2010 anyway) do automatic line continuation. So, if you're seeing VB.NET throw up these errors, you have to reformat your SQL string like this:
my query1 = "SELECT Inventory.Inventory_Id, Inventory.Inventory_description, " & _
"Inventory.Inventory_stock_count, nz((SELECT Sum(Order.item_qty) AS SumOfitem_qty " & _
"FROM [Order] " & _
"WHERE Order.From_date<=Date() AND (Order.To_date)>=Date() AND Order.Item_ID=""I"" & " & _
"Inventory.Inventory_Id),0) AS CurrentlyOut, " & _
"[Inventory_stock_count]-Nz((SELECT Sum(Order.item_qty) AS SumOfitem_qtyFROM [Order] " & _
"WHERE Order.From_date<=Date() AND (Order.To_date)>=Date() AND Order.Item_ID=""I"" & " & _
"Inventory.Inventory_Id),0) AS NetHereFROM Inventory"
Learn how VB.NET handles string literals before you start bashing other people for their "lack of knowledge", Mr. Genius.
|
|
|
|
|
Dave Kreskowiak wrote: VB.NET doesn't (until 2010 anyway)
hahaha yes it does in vs 2010 correct your knowledge download it & try it
your copy paste is irrelevant because i wrote it on one single line,
when i call you mr genius Mr mvp i am too humble to accept that title from you so keep it for yourself
Share your knowledge it's one way to achieve immortality
http://www.rabihtawil.com
http://blog.rabihtawil.com
http://www.coderisland.com
|
|
|
|
|
Say I wanted to create a small program that automatically rotated between websites every X seconds, where would I need to start? For instance, I create a simple form, it has 2 buttons. A start and a stop button. The stop button just quits the program completely, so I'm using the Me.Close() function for that, so I'm not worried about that. However, I want the start button to do something like.....open Google in Internet Explorer, and after say...45 seconds, rotate to Yahoo, and then another 45 seconds, rotate to MSN, and so forth and so on. Now, say I wanted the rotations to be less than 2 minutes, but more than 30 seconds, where would I start there? Would I use the Do/Loop functions?
|
|
|
|
|
This is trivial. Just use a timer.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
So glad this is trivial to an expert like yourself. However, being a beginner, the question still begs to differ. So, I go to using a timer, that's fine, but where do I begin? How do I launch the websites and make them rotate? Which function do I do? Obviously it won't be a Do-<whatever> function. Where would you suggest I start? And since it's trivial, let's do it this way. I want to make the timers connect to and then jump through using proxy. I.E., when the program is first launched, I want it to connect to a predefined proxy server and run through all the websites one time. Then on it's return path (or loop if you will), I want it to connect to a second predefined proxy server and have it run through the websites like that, so forth and so on. Any suggestions for that?
|
|
|
|
|