|
Hi,
We are parsing csv file to XML document. It follows a structure. One part has changed.
<code>
<PRODUCTS>
<PRODUCT INVOICE="2" PRODID="1 No Lead" QTY="3000" />
<PRODUCT INVOICE="2" PRODID="3 Super" QTY="1000" />
<PRODUCT INVOICE="2" PRODID="4 Diesel" QTY="1000" />
</PRODUCTS>
</code>
In this case we need to add a
<PRODUCT INVOICE="2" PRODID="2 Plus" QTY="0" />
If a product doesn't exist need to add that name with qty 0. How would we go about doing this? We are adding this to PRODUCT node.
Thanks.
-- modified at 12:59 Wednesday 19th July, 2006
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode productsNode = xmlDoc.ChildNodes[0].ChildNodes[0];
XmlElement productElem = xmlDoc.CreateElement("PRODUCT");
XmlAttribute invAttr = xmlDoc.CreateAttribute("INVOICE");
invAttr.Value = "2";
XmlAttribute prodidAttr = xmlDoc.CreateAttribute("PRODID");
prodidAttr.Value = "2";
XmlAttribute qtyAttr = xmlDoc.CreateAttribute("QTY");
qtyAttr.Value = "0";
productElem.Attributes.Append(invAttr);
productElem.Attributes.Append(prodidAttr);
productElem.Attributes.Append(qtyAttr);
productsNode.AppendChild(productElem);
|
|
|
|
|
Thanks for the reply.
Reading the values from a csv file, which has rows for the different product/fuel types. Sometimes there are 3 rows for Lead, Plus, super. so, want to add another line in XML document for diesel, with quantity 0. that way, there are alwasy 4 rows in the XML document.
|
|
|
|
|
Consider adding all four with value zero to each products node, then updating with values from the CSV file...
|
|
|
|
|
Hi all!
I need some solution, to do a "low level" logging for my application. In teh log, I want to see everything like function calls, strak trace, button events, textbox events.... like the profilers do.
Until now, I write my own loging system, and send messages to the logfile by hand like this:
Log.LoggThis("Something went ok",LogType.Message); or Log.LogThis("some error occured",exception,LogType.Error);
But I think is there a better vay to do this vithout hand coding in every method, and event handler....
If anybody have some idea, please wrote it to me.
Thanks, and sorry for my bad english.
|
|
|
|
|
|
Thank's I alredy know about NLog, and it's a good thing, but it's do the same, like my own loging engine.
Nlog write to file, what you want, but you must tell it, what, where, and when. So it isn't automatic, and still ned to write the logging messages into the code.
My solution has 3 projects, and a lot of forms, and classes witch have a tonn of functions, and events, so I don't want to write logging procedure for each method...
If you ever yuse some profiler, like Ants, or ReSharper yo see te way I like. These pograms need only the target application executable fle, and they listen into the app code, and tell you what happend in where, ad the target application don't need to modyfi.
-- modified at 16:59 Wednesday 19th July, 2006
|
|
|
|
|
I think you can solve this issue by using .NET Reflection. Take a look at this article (TraceListeners and Reflection)[^] - it contains enough to get you started.
In the example, the author of the article shows how to log information such as the calling function on the stack and the argument list of that function. He also explains how you retrieve information about the call stack.
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Tank's for the answer!
I try to use the refered article, to work out the correct solution.
-- modified at 3:37 Thursday 20th July, 2006
I checked the article, its good, but isn't do what I want. This type of logging stil need to be modyfy the target program.
I need solution to log a program/process without modifying it's code...
|
|
|
|
|
My progress bar in the status bar doesn't want to run.
The application I created is a SQL tool for an oracle db I work on. Basically, I just type my SQL code in a RichTextbox and then the data comes back in my datagrid. That works fine.
I thought it would be cool if I could add a progress bar and set it to marquee while I was waiting for my data to come back.
I'm pretty sure I need to multi-thread this beasty but when I do I get the following message: "Cross-thread operation not valid: Control 'rtbSQL' accessed from a thread other than the thread it was created on."
Here's what I passed to the new thread (which is created when I click the run button):
btnRunSQLClick(bla bla...)
{
Thread t1 = new Thread(new ThreadStart(GetData));
t1.Start();
}
the GetData() code:
public void GetData()
{
try
{
da=new OdbcDataAdapter(this.rtbSQL.Text, this.cnn);
cb=new OdbcCommandBuilder(da);
dt=new DataTable();
da.Fill(dt);
}
catch(OdbcException ex)
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.dataGrid1.DataSource = dt;
}
Any ideas? I'm definitely a novice at threading!!
|
|
|
|
|
If you are using 2.0 you could use BackgroundWorker and subscribe to the OnProgressChanged event to update your progressbar.
Otherwise you need to use an event to update your progressbar in the UI thread or use invoke on the progressbar to update it.
Take a look on this site for some good examples of multi-threading
|
|
|
|
|
The problem is the following line: da=new OdbcDataAdapter(this.rtbSQL.Text, this.cnn); . As the error message says accessing a control a thread other than the thread it was created on isn't allowed.
You should retrieve the value of the this.rtbSQL.Text property before starting the worker thread and then pass it to the method. Therefor you could either use this overload of the Thread.Start method[^] or follow techniques presented in this MSDN article[^].
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
I want to read a very large files such az log files in IIS line by line with an especial format for each line (by c#),Which way or function do you recommand?
-- modified at 11:37 Wednesday 19th July, 2006
|
|
|
|
|
StreamReader reader = new StreamReader("MyFile");<br />
string strLine;<br />
<br />
while( (strLine = reader.ReadLine() ) != null )<br />
{<br />
}
|
|
|
|
|
tail ?
(download cygwin)
or perhaps
// warning, pseudo-code, if it doesn't compile => fix the code yourself
static void Main(string[] args)
{
string line;
using(StreamReader sr = new StreamReader(args[0]))
while((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
Console.ReadLine();
}
}
|
|
|
|
|
Hello
first of all thanks for answer,So Fast!
Look
the problem is that these are huge file,Maybe 1G...
The solution that you recommanded ,have problem of speed,I want a solution that read file faster.
Thanks in advance
|
|
|
|
|
It is two parts, one you have to use a stream with a file so big because you do not have the memory to do otherwise. Secondly, if the file is not indexed your SOL. If it is indexed you can use any traversal algorithm to get the data you need. ( I did this technique with the national do not call list and it works fairly fast)
Also, you may consider c++ if you just need speed.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Also, you may consider c++ if you just need speed.
I'm not sure how much that would help though. The filesystem would still be the bottleneck in performance.
|
|
|
|
|
You can use memory mapping in C++ which will reduce the bottle neck for speed.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
what is it you want to do?
the question was: "I want to read a very large files"
I told you how to read without memory problem.
Now it can't read faster than you!
Had the question be: "I am looking for a particular pattern" I might have added an automated search function.....
But if you want to read it all, you've got to do it man!
|
|
|
|
|
I have a loop to send aysn message to different clients as below.
but even if all the clients are online and the configuration of all the clients are the same, I can only received a part of responses from clients.
Would you pls give me some suggestion about this problem?Thank you
code below------------------------------------------------------------------
foreach (IPEndPoint endPoint in this.endPoints)
{
try{
udpClient = new UdpClient();
udpClient.Connect(endPoint);
udpClient.Send(buf, length);
udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), new UdpState(udpClient, endPoint));
}
catch (Exception ex){
}
----------------------------------------------------------------------------
Sincerely,
WeiYu Wang
|
|
|
|
|
Hi,
i am using a windows DateTimepicker. When i click the up/down arrow button when the control is not having focus, it increments the value first and then sets the focus to control. If i want to do some validation before value changes, what event i should be handling? Basicall what i want is if the user click the up down arrow button, i want the mins field to increment instead of hours field. Format for my datetime picker is hh:mm:ss. By default the focus is on the hour field, i want the mins field to have focus.
any idea?
venkat
|
|
|
|
|
Have you tried the ValueChanged event
|
|
|
|
|
i cannot do on value change because if the user himself changes the focus to hour field and then increments, value change should increment the hour. I just want to set the default field to increment as mins. ValueChanged event happens after the value has been changed, so i don't want to revert back. If the focus is not in the control, user clicks the updown button, it should change the min field instead of hour but if the control has focus and user has selected hour field it should change hour. I just want to change the default from hour to mins.
|
|
|
|
|
I'm working on some in-house software to calibrate a product. I've written code with MS Visual Studio Express C# on my PC, running XP and Office 2000. It uses "System.Runtime.InteropServices" and Excel and Office bits to communicate with Excel. It works fine.
When I come to try it out on the PC that will be used, there's an error about Interop being the wrong version when installing. That PC is also running XP, but has Office XP. I downloaded some runtime Interop for Orfice 2003, and XP, but they didn't make any difference. Do I need the targe systems version of Office to make an application that will install and run?
|
|
|
|