|
Is there a reason you're not using linq-to-xml? It's much simpler (types from memory, so you may need to tweak it a bit)...
XDocument doc = XDocument.Load("myfile.xml");
XElement root = doc.Element["Rooms"];
foreach (XElement element in root.Elements)
{
int roomID = Convert.ToInt32(element.Element["RoomRQID"].Value);
int quantity = Convert.ToInt32(element.Element["Quantity"].Value);
int numAdults = Convert.ToInt32(element.Element["NumAdults"].Value);
}
No messing around with InnerText and that kind of crap.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I have a regular DataGridView and RowHeadersVisible is set to true. How do I get the location and size of the cell in the upper leftmost corner (the one to the left of the headings)?
|
|
|
|
|
DataGridView[0,0].value!!!!
|
|
|
|
|
Thanks, but I figured it out finally:
DataGridView.GetCellDisplayRectangle(-1, -1, true)
|
|
|
|
|
hw can i append text to end of a file?
|
|
|
|
|
System.IO.File.AppendAllText( string path, string contents )
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
MSDN link Here[^].
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
Dear all,
I want to create a large .txt file but when i run my code i got a strange thing,
A messagebox say's: "No Symbols are loaded for any call stack frame. The source code cannot be displayed."
and a warning say's "The CLR has been unable to transition from COM context 0x1c2000 to COM context 0x1c2170 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations."
My code is:
string prev="";<br />
<br />
string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=E:\\ICA_Newspapers.mdb";<br />
<br />
OleDbConnection conn = new OleDbConnection(connectionString);<br />
<br />
string sql = "SELECT * FROM All_Analyzed_Corpus";<br />
<br />
OleDbCommand cmd = new OleDbCommand(sql, conn);<br />
<br />
conn.Open();<br />
<br />
OleDbDataReader reader;<br />
reader = cmd.ExecuteReader();<br />
<br />
StreamWriter tw = new StreamWriter(Application.StartupPath + "\\TaggedCorpus.txt");<br />
<br />
StringBuilder text = new StringBuilder();<br />
<br />
<br />
while (reader.Read())<br />
{<br />
if (reader.GetValue(1).ToString() == "/D")<br />
{<br />
text.Append("</s>");<br />
<br />
tw.WriteLine(text);<br />
tw.Flush();<br />
text = text.Remove(0, text.Length);<br />
<br />
text.Append("<s> ");<br />
prev = "/D";<br />
}<br />
else if (reader.GetValue(1).ToString() == "/T" && prev != "/D")<br />
{<br />
text.Append("</s>");<br />
tw.WriteLine(text);<br />
tw.Flush();<br />
<br />
text = text.Remove(0, text.Length);<br />
<br />
text.Append("<s> ");<br />
prev = "/T";<br />
}<br />
else if (reader.GetValue(1).ToString() == "/P" && prev != "/T")<br />
{<br />
text.Append("</s>");<br />
tw.WriteLine(text);<br />
tw.Flush();<br />
<br />
text = text.Remove(0, text.Length);<br />
<br />
text.Append("<s> ");<br />
prev = "/P";<br />
}<br />
<br />
<br />
<br />
if(reader.GetValue(5).ToString().Contains("/"))<br />
{<br />
pr1 = reader.GetValue(5).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
pr1 = reader.GetValue(5).ToString();<br />
}<br />
<br />
if (reader.GetValue(6).ToString().Contains("/"))<br />
{<br />
pr2 = reader.GetValue(6).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
pr2 = reader.GetValue(6).ToString();<br />
}<br />
<br />
if (reader.GetValue(7).ToString().Contains("/"))<br />
{<br />
pr3 = reader.GetValue(7).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
pr3 = reader.GetValue(7).ToString();<br />
}<br />
if (reader.GetValue(8).ToString().Contains("/"))<br />
{<br />
stm = reader.GetValue(8).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
stm = reader.GetValue(8).ToString();<br />
}<br />
<br />
if (reader.GetValue(9).ToString().Contains("/"))<br />
{<br />
suf1 = reader.GetValue(9).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
suf1 = reader.GetValue(9).ToString();<br />
}<br />
<br />
if (reader.GetValue(10).ToString().Contains("/"))<br />
{<br />
suf2 = reader.GetValue(10).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
suf2 = reader.GetValue(10).ToString();<br />
}<br />
<br />
if (reader.GetValue(14).ToString().Contains("/"))<br />
{<br />
cas = reader.GetValue(14).ToString().Split(char.Parse("/"))[1];<br />
}<br />
else<br />
{<br />
cas = reader.GetValue(14).ToString();<br />
}<br />
<br />
<br />
text.Append(pr1 + "+" + pr2 + "+"<br />
+ pr3 + "+" + stm + "+" + suf1<br />
+ "+" + suf2 + "+" + cas + " ");<br />
<br />
<br />
text = text.Replace(" +", " #+");<br />
text = text.Replace("+++", "+#+#+");<br />
text = text.Replace("++", "+#+");<br />
text = text.Replace("+ ", "+# ");<br />
<br />
<br />
}<br />
<br />
tw.Close();<br />
<br />
reader.Close();<br />
conn.Close();<br />
<br />
Thanks in advance...
|
|
|
|
|
It seems that a COM object needs to respond within 60 seconds, but you create someting in this time.
Is this an operation you run in your main tread (or the thread which created a window)?
I would try to execute Application.DoEvents(); every loop iteration.
Greetings
Covean
|
|
|
|
|
When I did Application.DoEvents(); no message appears but the file size stopped at 7805 kb and the program stopped and thats cant be because the file must end with the last record in my database table.
|
|
|
|
|
Are there no exceptions?
I looked over your code and couldn't find any problem, so I tried if there is maybe a problem with the filesize (I haven't really awaited that there is an error and there is no error. I was able to create an 9GB large text file without problems).
Do you use any other COM-objects in your project?
At next I would try to do this database-"export" in an own thread.
Greetings
Covean
|
|
|
|
|
Hi, in my database I have a bunch of sums which for example can be broken down to (100*25)/3 or whatever the case may be.
How would I work out programatically the sum in the string in my C# app?
Thanks.
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
Good question. I had thought .NET provided something for doing that sort of thing, but can't find it.
There are a number of projects on the net which provide functionality for doing that sort of thing. Here's one:
http://www.bestcode.com/html/bcparser_net.html
Regards,
Rob Philpott.
|
|
|
|
|
|
|
Hi,
I want to convert my text file to pdf file ?
is it possible in C#?
Thanking You
Sunil G.
modified on Monday, January 11, 2010 5:00 AM
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:13am.
|
|
|
|
|
I think PDFSharp is third party component.
I dont want to use third party.
|
|
|
|
|
You don't have a choice. There is nothing in the .NET Framework that reads/writes .PDF files natively.
|
|
|
|
|
Id PDFsharp copyrighted or free source ?
Can i use PDFSharp in my C# application?
Can u give the component?
|
|
|
|
|
|
hi..
what is the maximum buffer size in c#.
while i use
byte [] byte = new byte [MAX];
how much will i set maximum value MAX variable.
have ant restriction to set maximum buffer size . can i use this long.MaxValue
Thanks.
|
|
|
|
|
The effective limit is how much RAM your users are going to have.
Int32.MaxValue is about 2GB, which is probably too much to assume is present on your users' machines
Int64.MaxValue is about 1019 which is a ridiculously large number.
Why do you need such a large buffer in the first place? You might want to re-think your algorithm.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
i will consider ... thanks for your reply
|
|
|
|
|
Dear developers,
I am coding a very small project for my study. I want to refresh form1 after form2 is closed. For example, I open form1 and click one button to open form2 and in form2 I can insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too. So, after inserting data from form2 and when I close the form2, I want the comboxbox in form1 refresh to retrieve the last update of tblItem data.
Please advise, thanks.
Visoth
Chuon Visoth
Angkor Wat - Cambodia
asp.net - c sharp beginner
|
|
|
|