|
Yes, that's why it didn't show up.
It write's xml. And that's the point.
The whole func:
public void SaveXML(string path)
{
StreamWriter SW = new StreamWriter(path, false);
SW.Write("<Neural Network>");
for (int l = 0; l < Layers.Length;l++ )
{
SW.Write(" <Layer>");
for (int n = 0; n < Layers[l].neurons.Length; n++)
{
SW.Write(" <Neuron number=\"" + GetNumber(this[l][n]) + "\n>");
SW.Write(" <Output value=\"" + this[l][n].output + "\n/>");
SW.Write(" <Weights>");
for (int w = 0; w < this[l][n].weights.Count; w++)
SW.Write(" <weight value= \"" + this[l][n].weights[w] + "\"/>");
SW.Write(" </Weights>");
SW.Write(" <Dendrites>");
for (int d = 0; d < this[l][n].dendrites.Count; d++)
{
SW.Write(" <dendrite number = \"" +GetNumber(this[l][n].dendrites[d]) + "\"/>");
}
SW.Write(" </Dendrites>");
//this[l][n].weights;
SW.Write(" </Neuron>");
}
SW.Write(" </Layer>");
}
SW.Flush();
SW.Close();
}
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|
|
OK - given that you posted Write("") twice, and Colin brought it to your attention, you'd understand our confusion..
Your code works fine here - I took out the bit that iterates through the nodes, ran it and ended up with a file that was populated with XML. I have VS.NET 2003.
Is there an exception block somewhere that could be throwing silently, and thus causing the code to never Flush ? Try a flush before the loop that iterates through the nodes and see what you get, then try a try/catch locally in this code to see what the error is, if any.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I looked at wrong file...
Thank you all.
|
|
|
|
|
Sorry - had some extra thoughts and edited the reply. Basically, if an exception is thrown while iterating through the nodes, and is caught without notification by the code that calls this function, you may end up with an empty file, as no flush will occur. Try a flush before the loop and if you get the first open node in the file, that's probably what is going on.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I don't have eny exception handling yet...
It works now, so I'm not doing anything with it
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|
|
It started working ? Cool. Can't imagine what was wrong before then...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I looked at the wrong file.
There was 2 files one in the place I thought it would be and another that was where the program thought it should be...
The PROgrammer Niklas Ulvinge aka IDK
|
|
|
|
|
Niklas Ulvinge wrote:
The file is empty.
Based on the code that I see that is the result I would expect.
As I've said you need to write stuff to the file. For example:
SW.Write("Some text goes here");
If you leave nothing in between the quotation marks then nothing will get written to the file.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
He's writing XML and didn't tick the box to show XML in his posts.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Hey everybody!
I have a small question about the FileMode.Append .
as far as I understood using the FileMode.Append, the serialization method will look for the end of the file and will serialize from there, so I can add objects to the file without overwriting the old information.
so lets say I have 3 objects in a file, and I added another object.
so in total I have 4 objects.
just for the example I'll compare it to a listbox.
we had 4 strings added by the user, all being saved using FileMode.Append (one by one).
but what if I want to remove a specific string (an object, a specific "string name") from the file. lets say the 2nd string (or object) that I saved.
is there a way to do that? some other way of using Append ???
thanks alot!
|
|
|
|
|
If you really want to remove it from the file you will have to rewrite it completely. This could be done by first deserializing it and then serieliazing the lements you wish to remain into another file (or overwriting the existing one). If you somehoew store the positions of the objects in the file you could also copy parts of it without serialize mechnisms into a new file.
Surely this will slow down performance. Another idea would be to just the leave the file as it is but skip those values you dont need while deserializing. You would then just clean up the file every once in a while.
|
|
|
|
|
|
Just an idea, what if you have a collection of objects, and everytime serialize and deserialize the whole collection? That way, you could in code add, remove, or change the items, and serialization would be automatic.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello,
I created an xml file and created a class matching that file using xsd.exe tool. Im inserting data from the file to an instance of the class using serialization:Instance=(casting)XmlSerializer.Deserialize(FileStream),
and Im saving changes to the xml file:
XmlSerializer.Serialize(FileStream,Instance).
My problem is that sometimes when storing data from the instance of the class to the file destroys the fomat of the xml file and the file can no longer load unless I change it back. The format is destroyed by adding xml tags that belong to the file but not in the right place. This happens when I use the folderBrowserDialog to change one of the parameters of the instance and only on specific chosen directory of the dialog.
|
|
|
|
|
hi folks,
i am looking for some ideas as how i could go about adding icons to a context menu ??? For my purpose, my context menu looks at a particular dir and appends all available files to the menu. Each file that gets appended to the context menu, the associate application icon also gets appended on the left handside of the filename. I know how to extract the file icons. But as how to append each of the icons to it's respective file in the context menu i have no idea about.
One idea I had was to use a delgate to invoke the OnDrawItem Event handler each time the context menu is invoked ? I havent attempted to do this yet. Now is this a possible solution or are there alternatives i dont know about ??
i would appreciate any feedback.
thanks
|
|
|
|
|
well i had received an email from an anonymous user at CP asking me if i had come up with a solution to my problem. Well yes and no is the response. No because i couldnt work out the delegate aspect of the solution. Yes because i saw another article in which the author used main menu and ownderdrawn method to append the icons.
The article is here :
http://www.csharphelp.com/archives/archive282.html
The article did provide me with an idea of how to tackle my problem. However, I have had other things to do so I havent had much time to try it out. If I have some time over the weekend or next week I will post back my solution.
so hope this helps.
cheers
|
|
|
|
|
I make a simple search like in database like this
sql="SELECT * FROM "+tableName+
" WHERE "+this.cbColumn.Text+
" LIKE '*"+this.tbKeyword.Text+"*'";
And I bind to datagrid -> no result value display
But when i test in Access Query with this sql string. It showed the result.
Can anybody help me ! Thankz for reading.;)
|
|
|
|
|
Two things:
1. The wildcard character in SQL is % , not * like in Windows or Access.
2. If you are accessing the database with that SQL string, use parameterized queries. By concatenating strings, you are subject to SQL injection attacks. See the Parameters property of the SqlCommand class.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Luis Alonso Ramos wrote:
By concatenating strings, you are subject to SQL injection attacks.
Looks like I have to be quick around here to point out security problems in SQL!
However, if you look again you will see that the table name is one of the things he is injecting and that cannot be inserted in to a parameter without some extra work and some compromise.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Colin Angus Mackay wrote:
Looks like I have to be quick around here to point out security problems in SQL!
Yeah, I'm working hard on it!!
Colin Angus Mackay wrote:
you will see that the table name is one of the things he is injecting and that cannot be inserted in to a parameter
I hadn't noticed it, but now I read your answer, and all I can say is cool!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
As Luis said the wildcard in SQL Server (and most other database systems) is the % percent sign.
Also, he mentioned that you should use parameterised queries, however in your case this is going to be more problematic as you are injecting the table and column names into the SQL statement - something that is not easily parameterised.
What I suggest is that you create a stored procedure for this and in the stored procedure accept the table and column name as parameters. You can then verify that these values are valid.
I have to admit that I couldn't figure it out in a single stage. So here is a safer solution that I present:
CREATE PROCEDURE dbo.BuildSelectStatement
@tableName sysname,
@columnName sysname
AS
-- First, check that the table exists
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = @tableName
AND TABLE_SCHEMA = 'dbo'
AND TABLE_TYPE = 'BASE TABLE')
BEGIN
SELECT '' AS result;
RETURN
END
-- Second, check that the column exists in the table
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @tableName
AND TABLE_SCHEMA = 'dbo'
AND COLUMN_NAME = @columnName)
BEGIN
SELECT '' AS result;
RETURN
END
-- Everything is fine, build the SQL Statement.
SELECT 'SELECT * FROM ['+@tableName+'] WHERE ['+@columnName+'] LIKE @comparison' AS result
GO
The above stored procedure will send back an empty string if the data is invalid, or a SQL Statement if the result is fine.
Then in your code you can write something like this:
SqlCommand buildSqlCmd = new SqlCommand("BuildSelectStatement", myConnection);
buildSqlCmd.CommandType = CommandType.StoredProcedure;
buildSqlCmd.Parmaters.Add("@tableName", tableName);
buildSqlCmd.Paramters.Add("@columnName", this.cbColumn.Text);
string sqlStatment = (string)buildSqlCmd.ExecuteScalar();
if (sqlStatment == "")
{
}
SqlCommand runQueryCmd = new SqlCommand(sqlStatement, myConnection);
runQueryCmd.Parameters.Add("@comparison",
string.Format("%{0}%", this.tbKeyword.Text));
SqlDataReader reader = runQueryCmd.ExecuteReader();
Does this help?
DISCLAIMER: I typed all this in directly, it has not been tested, there may be minor errors
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Clearly and helpful.You're so nice.
Thankz for both of ur helps!
BlueDot
|
|
|
|
|
Hi all
I want to write a program that will read a text file as an unput. This file will contain some info for students, one student in one line. It might contain 60,000 to 500,000 lines.
Now the program shoul read each line and store the info. into the database.
My question is:
What is the fastest way for doing that?
inserting the data into the database must be through the program(not importing the data through the SQL Server or MS Access).
Would u help me please
|
|
|
|
|
First of all you will need to open a connection to the database. Depending on which db you want to write to choose one of the providers coming with the framework (OleDb, ODBC...). If you need it fast you'll probably have to test them.
If its possible I would define a stored procedure in the database. Otherwise you will have to make a parameterized query. Once this is done the reading can begin.
You will now need a FileStream to open the file and read it line by line. Depending on the format you will have to split each line some way and fill in the parameters to your query. Execute it and go fopr the next line.
Thats it.
|
|
|
|