|
This sounds like a reasonable thing to do with an assembly hosted by SqlServer 2005, but I'm not sure if it's really necessary to jump through extra hoops just for simple logging. Could you not, for example, create a table which stores the log messages (instead of writing them to a file)? That would probably be more performant than calling into an assembly, plus, you could query that table in various ways - something not possible with pure text.
Just a thought...
Josh
|
|
|
|
|
I have this code:
for (int i = 0; i < pnlControls.Controls.Count - 1; i++)
{
pnlControls.Controls.Remove(pnlControls.Controls[i]);
}
but, it doesn't remove the controls.
Can someone tell me how I correctly remove controls from the panel.
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
You should do a reversed iteration over the Controls, starting with int i = pnlControls.Controls.Count - 1; . This is necessary because if you remove items from a collection as you iterate over the collection (from start to end), every time an item is removed, the other items shift their index to fill the open space. For example, when you remove item[0], item[1] moves into [0], and item[2] moves into [1], etc.
Josh
|
|
|
|
|
Josh Smith wrote: int i = pnlControls.Controls.Count - 1
Referring to objects in a collection using an index is ugly to me anyways and reminds me of ugly VB code.
But, I found my problem. I had an issue in the container object. To long to explain.
Thanks for helping.
It was just crap code to see its working or not.
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Hello everybody.
Sometimes my application (even in debug mode) fails to continue on the opening command when Im trying to open some COM-port:
SerialPort p = new SerialPort(port);<br />
p.Open();
...
Application do nothing. No CPU time spending, no memory spending...
But sometimes it`s all ok. And there`s no any problems in the SAME methods with the same code.
try-catch blocks not helps in this case.
Problem can be solved by restarting PC or by reconnecting devices connected to COM-ports.
But it is very and very not desirable.
Anybody knows how I can solve this with my code ?
Many Thanks,
Eugene Ostroukhov.
|
|
|
|
|
Hi,
I get errors reading an xml file with my MDA, and its because of this header in the xml file:
<?xml version="1.0" standalone="yes"?>
How can i remove it and make sure that its not comming back?
Manually didn't work...
|
|
|
|
|
Use XmlWriterSettings and set the ConformanceLevel to Fragment . Then, use XmlWriter.Create() to create your writer with the settings.
Logifusion[^]
|
|
|
|
|
Actually, you can also set OmitXmlDeclaration to true. Here's a code snippet to show you how it works with an XmlSerializer (which doesn't let you set the conformance level to Fragment ).
XmlSerializer xs = new XmlSerializer(obj.GetType());
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.Indent = true;
xws.IndentChars = " ";
xws.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create(new StringWriter(sb), xws);
xs.Serialize(xw, obj);
return sb.ToString();
Logifusion[^]
|
|
|
|
|
Hi,
What does OmitXmlDeclaration do?
And do i need all that code to use OmitXmlDeclaration?
Because all i want is to prevent that header being added in the xml file.
Thanks in advance!
|
|
|
|
|
OmitXmlDeclaration[^]
The code is an example. You have to be writing to the xml file somehow, so just use XmlWriter and XmlWriterSettings .
Logifusion[^]
|
|
|
|
|
Hi,
I am writing. But im more like appending from xml file to another xml file.
All i use is the WriteXml("xmlfile.xml"); method which keeps remaking the file.
If i manually remove the header, it comes back after an appending has taken place.
So basically im not using xmlwriter(settings).
Im using DataSet to do this.
So how can i prevent the header being added in the file?
|
|
|
|
|
Umm, DataSet.WriteXml is overloaded to take an XmlWriter .
DataSet ds = ...;
XmlWriterSettings xws = new XmlWriterSettings();
xws.Indent = true;
xws.IndentChars = " ";
xws.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create("xmlfile.xml", xws);
ds.WriteXml(xw);
Logifusion[^]
|
|
|
|
|
Hi,
Its not adding the header anymore.
But now i get these strange characters before my root tag:
<root>
How come?
|
|
|
|
|
Not sure. My best guess is that the encoding is messed up. Try different settings for the Encoding property.
Logifusion[^]
|
|
|
|
|
Hi,
I tried: xws.Encoding = Encoding.Default;
That worked.
I thank you for your time Dustin!
|
|
|
|
|
Hi,
Is there any way in Dot Net or VC through which i could determine the IP addresses and/or Computer Names of all the computers on a local area network. Any help or link would be highly appreciated...
Regards,
Wasif Ehsan.
|
|
|
|
|
I think you might want to check out using Active Directory to retrieve info like that. Try this article[^] for example.
Josh
|
|
|
|
|
I think what Josh said is good advice.
There is another way to attack the problem, if you're interested. You could send out ARP (Address Resolution Protocol) requests to IPs on the whole network and see what responses you get. An ARP request is broadcasted to the whole network and it basically asks the question: "Who has IP address www.xxx.yyyy.zzz?". Each device on the network looks for such packets and will reply to the sender with its MAC address, which then allows the sender to associate an IP Address with a MAC address so that it knows how to get packets to that device.
For example, let us say that you are on a computer whose IP address on the LAN is 192.168.2.33. You want to know what other computers are out there, specifically on the subnet 192.168.2.x. Let us further say that there are three more machines on that subnet: 192.168.2.50, 192.168.2.67, and 192.168.2.4. Your computer sends out a whole slew of ARP requests, like this (this is what it might look like in a packet sniffer):
From: 192.168.2.33 BROADCAST --> who has 192.168.2.1 ?
From: 192.168.2.33 BROADCAST --> who has 192.168.2.2 ?
From: 192.168.2.33 BROADCAST --> who has 192.168.2.3 ?
From: 192.168.2.33 BROADCAST --> who has 192.168.2.4 ?
....
From: 192.168.2.33 BROADCAST --> who has 192.168.2.255 ? Now when those three machines see their addresses asked for, they reply to your computer like so:
From: 192.168.2.50, To: 192.168.2.33 --> 192.168.2.50 is at [some MAC Address]
From: 192.168.2.67, To: 192.168.2.33 --> 192.168.2.67 is at [some MAC Address]
From: 192.168.2.4, To: 192.168.2.33 --> 192.168.2.4 is at [some MAC Address] Now, when your computer picks those messages up, it knows how many computers are on the subnet 192.168.2.x and what their IP addresses are. From there to getting the computer names would not be hard.
This is just another idea, if you want a more low-level method of solving the problem. In order to send and receive packets from your application, doing a quick article search on CodeProject for "sending packets" or "receiving packets" should pull back some helpful results.
I hope this gives you some ideas; doubtless there are other ways of doing it, and perhaps more efficient than this one.
Sincerely,
Alexander Wiseman
|
|
|
|
|
That's very interesting. Thanks for taking the time to write it!
Josh
|
|
|
|
|
No problem. Thanks for the Active Directory link!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Can anybody confirm what the correct syntax is for using the #ifdef DEBUG statement is?
I am attempting to do something like this:
private bool CheckLogon(string username, string password)
{
#ifdef DEBUG
return true;
#endif
...
snipped code that does release logon checks
...
return checkLogonResult;
}
However this gives a preprocessor directive compiler error.
According to google the syntax above is correct, so I must be committing some stupid mistake
|
|
|
|
|
use #if instead of #ifdef. #ifdef is a C++ directive, not C#.
Josh
|
|
|
|
|
The shame of it
Thanks though
|
|
|
|
|
You beat me to it
Sincerely,
Alexander Wiseman
|
|
|
|
|