|
hi,
It may be slightly slower - after all XmlDocument internally uses XmlReader . Main problem with XmlDocument is that it constructs whole DOM in memory - which makes it unusable for biger files and slower/more resource expensive for "medium-sized" files.
But XmlDocument is really good when it come to tree operations with XML data.
One more solution would be use of XPathDocument , it's smaller overkill then XmlDocument (but slower/more expensive then XmlReader s) and it's fairly easy to use... actualy same use as XmlDocument in this case.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Thanks for the information =) in this case i will stick to XmlDocument becourse the xml file is not to big, and i will only use it when the program opens and close
BestRegards
SnowJim
|
|
|
|
|
Hello,
I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address, to HIS port 8801.
This means that I need to bind my sender socket to (myaddress,8801), use it for the send, then shut it down and close it. Then I want to wait, say 30 seconds, and do it all over again. Naturally, the socket's ReuseAddress property must be set for this to work.
However, in practice, the second time I bind a socket to my local endpoint, I get a SocketException: "Only one usage of each socket address (protocol/network address/port) is normally permitted."
Can anyone help me? The following code attempts to send a string containing the date/time to a server on 192.168.2.10:8810. If I set the "bindIt" variable to false, the code works fine. If I try to bind (and re-bind) the socket to the same local endpoint (e.g, I've set bindIt to true), the code fails with the above exception. Help!
Thanks
Greg Hassett
using System;<br />
using System.IO;<br />
using System.Net;<br />
using System.Net.Sockets;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
class TcpClientTest <br />
{<br />
static public void Main() <br />
{<br />
bool bindIt = true;<br />
<br />
IPHostEntry localHostEntry = Dns.GetHostByName(Dns.GetHostName());<br />
IPEndPoint localIPEndPoint = new IPEndPoint (localHostEntry.AddressList[0], 8801);<br />
<br />
while (true)<br />
{<br />
try<br />
{<br />
Console.WriteLine("Press return to send data");<br />
Console.ReadLine();<br />
<br />
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
<br />
socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);<br />
socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(false, 0));<br />
socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1);<br />
<br />
if (bindIt)<br />
{<br />
socket.Bind (new IPEndPoint (IPAddress.Any, 8801));<br />
}<br />
<br />
socket.Connect (new IPEndPoint(IPAddress.Parse("192.168.2.10"), 8801));<br />
<br />
byte[] buf = Encoding.ASCII.GetBytes (DateTime.Now.ToString());<br />
socket.Send (buf);<br />
<br />
socket.Shutdown (SocketShutdown.Both);<br />
socket.Close ();<br />
<br />
Console.Out.WriteLine ("Sent");<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.Out.WriteLine (ex.ToString());<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Does anyone know what exactly the term 'static' means in reference to web apps? Does this mean that there is only a single instance of the variable within the DLL itself and everyone who runs an instance of a particular page can modify the variable?
If this is the case then how does one hold values in page level variables and have them maintain there value when the page posts back (for autopostback objects...)?
Thanks in advance for anyone with a good explanation.
~LizardWiz()
|
|
|
|
|
static is static across AppDomains. AFAIK, ASP.NET creates a separate AppDomain for each application and so everyone who runs a particular page must get the same value.
I don't know if ASP.NET will unload appdomains during heavy load and reload them later, if that's true, then your static variables will be gone.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Everyone who runs an instance of a particular page can modify the variable. Each session gets it own copy of shared property.
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|
|
If you are running your web application on multiple web servers, the static data will be local to each server
60% of statistics are made up on the spot
|
|
|
|
|
Ladies and Gentlemen, I am STUCK!
This is just a test webservice. All I want to do is get the unitprice from the Products table and multiply it by the "howmany" variable.
I'm stumped at how to get the Unitprice out of the dataset.
Here's the code:
[WebMethod]
public float HowMuchWillItCost(string productName, int howMany)
{
try
{
sqlDA.SelectCommand.CommandText = "SELECT UnitPrice from PRODUCTS WHERE ProductName = '" + productName + "'";
sqlDA.Fill(ds11, "price");
float price;
price = (float)ds11.Tables["Products"].Rows[0]["UnitPrice"];
return price * howMany;
}
catch(Exception e)
{
throw new Exception("Error calculating cost: " + e.Message);
}
}
|
|
|
|
|
When posting some problem its always good if you also post the error message and probably also a stack trace.
I think your problem lies in the Fill statement. Try to take the same name when accessing the Tables property:
sqlDA.Fill(ds11, "Products");
Also check for the data types in the result. Its always safer to use Convert instead of just casting:
price = Convert.ToSingle(ds11.Tables["Products"].Rows[0]["UnitPrice"]);
Its also a good idea to check for DbNull before doing this.
|
|
|
|
|
I appreciate your help. I'll give it a try.
|
|
|
|
|
That worked like a charm. Thanks!
If you happen to stop by again, could you point me to an easy way to cycle through a dataset?
Easy in the relative sense of the word.
Muchos gracias.
|
|
|
|
|
Ok. First of all one DataSet can consist of several tables which can be accessed (like you already did in your example) with the Tables property. You can also iterate through all tables with
foreach (DataTable dt in myDataSet.Tables) {
}
When you have one DataTable object you can then iterate through its rows:
foreach (DataRow dr in myDataTable.Rows) {
}
You can access the vakues of each DataRow via its indexer which accepts either the index of the column you want to access or its name. You can also use the ItemArray property to retrieve all items in one array.
An example to just print out every value of every row of every table in a DataSet (what a sentence ) could be:
foreach (DataTable dt in myDataSet){
Console.WriteLine("Printing Table: " + dt.TableName);
foreach (DataRow dr in dt.Rows) {
Console.Write("Row: ");
object[] data = dr.ItemArray;
for (int i = 0; i < data.Length; i++) {
Console.Write(data[i].ToString());
}
Console.WriteLine("");
}
}
|
|
|
|
|
This problem might have a simple answer but I can't figure it out. I have a richTextBox in which I am trying to implement a keyPress event. The event seems to fire every time a key is pressed except for when I press the DELETE key. Anyone know why this key will not fire the event? Any suggestions on how to create an event for the DELETE key? Any help would be appreciated. Thanks!
|
|
|
|
|
I don't know if it's a bug but yeah, Delete doesn't trigger a KeyPressed. You have to subscribe to the KeyDown event for that.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Oh, the keydown event does fire for the DELETE key. Thanks!
|
|
|
|
|
Dear Friends
I am developing my first program in C# when I have created the database connectivity in C# as below
SqlConnection mysqlconnection = new SqlConnection("server=murtuza; Trusted_connection=Yes;database=northwind");
OleDbConnection myconn = new OleDbConnection (@"Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=company;data source=murtuza;initial catalog=northwind;integrated security=SSPI;workstation id=ACER-157FBA01C8;packet size=4096");
OleDbCommand mycmmd= new OleDbCommand (myselect, myconn);
myconn.Open();
OleDbDataReader myreader;
myreader= mycmmd.ExecuteReader();
when i reach the myreader= mycmmd.ExecuteReader(); this statment i am getting error please can u tell me the simple way to connect to a sql server database
|
|
|
|
|
I'm confused by the use of SqlConnection in your first code example and OleDbConnection in your second.
And what is the error? Is it a connection error, or an error with your select statement?
Put a try-catch block around the ExecuteReader and inspect the Exception.Message property.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I'm not only confused by your usage of two connections but I'm also unclear what the error could be. Especially with client/server systems there could be any number of errors that are legitamate and at multiple locations. Please provide more information.
|
|
|
|
|
I am working with a fixed length file that I will be parsing at run time and inserting into a SQL table. I would like to store the insert statements in a table. The problem with this is that the file contains some EBCDIC characters that need to be converted to ASCII before inserting into the database. There are also other functions that need to be carried out on other fields before the data is pushed into the database tables. I don't want to hard code the insert statements as the file layout could change and it would be easier to change the insert statements than it would be to change and redistribute the program. Is there a way to evaluate the functions in the insert statements at run time?
|
|
|
|
|
JMichael2468 wrote:
There are also other functions that need to be carried out on other fields before the data is pushed into the database tables.
Do you mean, functions that have been coded in C# that you want to call, or SQL functions?
If the former, you can use reflection. If the latter, well, I don't know.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I want to Upload a file.
Here is my code..
Page 1:
WebClient client = new WebClient();
client.UploadFile( "http://ft-rt-005/test/upload1.aspx","POST","G:\\Water lilies.jpg");
Page 2:
foreach(string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs(Server.MapPath(".\\upload\\"+ file.FileName));
}
I am uploading a file to Page 2 using client.UploadFile().From Page 2 ,i am saving to the server.But whenever client.UploadFile() is invoked,my application searches the file in server.It is not searching in the client machine.
I want to upload from the client machine.Can anybody help me..
Thanks
Ramesh
|
|
|
|
|
i use this code to set the text of a second form from within another:
public string labelTitoloText
{
set
{
this.labelTitolo.Text = value;
}
}
but i get a compiler error until i use the keyword "static":
public static string labelTitoloText
{
set
{
this.labelTitolo.Text = value;
}
}
why?
|
|
|
|
|
static implies that the member method or field does not belong to any object but to the type itself but is available to all objects due to it. In short, there is no concept of "this " for something tagged static .
|
|
|
|
|
If you declare something static it means that you don't (as a matter of fact you can't) instantiate it before you use it. One of my favorite examples of the use of static is say you are writting a class that keeps track of how many instances of that particular object exists. Inside that class you declare a static variable that will have an initial value of zero. In the constructor of your object you increment that static variable by one and in the destructor you decrement that static variable by one to reflect the creation/destruction of your objects. Now, since it's a static variable you can't increment using the "this" keyword since that will refer to an instance variable. You need to use a the actual class name and then static variable to increment it to be like: MyClass.instance++ or MyClass.instance-- And since its a static variable that all of your classes "share" you could query that static variable from any of your instantiated objects because they will all have the same value.
Here's MSDN explanation of the keyword static: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfstaticpg.asp
|
|
|
|
|