|
I'm from a VB background where weaning off globals is almost essential, however I think there are some cases where a global (static class in C# I presume) is valid and this certainly sounds like one, how else are you to persist your data between functions?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
One of the reasons why global variables are bad is because everything in the program has access to them.
While reading up on singletons there seem to be just as many threads with the subject "Singletons are evil" as there are "Global Variables are evil".
How should i interpret what seems to be a bias against any and all sorts of persistent data?
How do people usually fix things like...
1: "Shopping cart" in webapplications, everything doesn't need to have access to the shopping cart but unless you store the shopping cart as a global or singleton(static class) you're going to lose whatever was in it.
2: Texture storage in games, same problem here, the sound manager for example doesn't need access to the textures, but unless you store the textures somewhere in the higher scope you're going to lose it all when the sound manager starts.
Still confused
|
|
|
|
|
Hi,
I have a DGV that load´s a table from a xml file, but after i make changes i can´t save them, see bellow. Help me debug this
Class_Helper.DataSet_Xml = new DataSet();
Class_Helper.Assembly_This = Assembly.GetExecutingAssembly();
Class_Helper.Stream_Resource = Class_Helper.Assembly_This.GetManifestResourceStream(Class_Helper.ResourceXml_login);
Class_Helper.DataSet_Xml.ReadXml(Class_Helper.Stream_Resource);
DataRow DataRow_user = Class_Helper.DataSet_Xml.Tables[0].NewRow();
DataRow_user["id"] = 10;
DataRow_user["f_name"] = ToolStripTextBox_FName.Text;
DataRow_user["l_name"] = ToolStripTextBox_LName.Text;
DataRow_user["username"] = ToolStripTextBox_Username.Text;
DataRow_user["password"] = ToolStripTextBox_Password.Text;
DataRow_user["role"] = ToolStripComboBox_Role.Text;
Class_Helper.DataSet_Xml.Tables[0].Rows.Add(DataRow_user);
DataGridView_Administrator.DataSource = Class_Helper.DataSet_Xml.Tables[0];
Class_Helper.DataSet_Xml.WriteXml(Class_Helper.ResourceXml_login, XmlWriteMode.WriteSchema);
Thanks
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hi. I need to send a http link to a asterisk server. It will use that link to call a script that will make certain calls to the thelephones in the company. Could someone explain how can i open a connection to the asterisk server?
|
|
|
|
|
Hi all,
How can I call MFC-dialog from managed code?
I tried to do this using platform invoke service but application core dumps because assertions deep in MFC.
Please advice.
Thanks
|
|
|
|
|
|
i am trying to read from an xml document but am not having any luck getting selectsinglenode to work
here is the code i am using
XmlDocument xml = new XmlDocument();
xml.Load(str); //str has the path to my XML doc
XmlNode xmln = xml.SelectSingleNode("/GPO/Identifier/Identifier");
//xmln is always null but xml has my xmldoc loaded in memory
string Identifier = xmln.InnerText.ToString(); //code bombs here cuz xmln is null...
here is the first few lines of the xml
<?xml version="1.0" encoding="utf-16" ?>
- <GPO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.microsoft.com/GroupPolicy/Settings">
- <Identifier>
<Identifier xmlns="http://www.microsoft.com/GroupPolicy/Types">{89AEAFFE-E1F8-4786-8AF7-6BE2D991625E}</Identifier>
i have 20 XSD schema files that are related to the xml docs i am trying to parse but i'm new to xml and not clear on how to use the xsd's
help in either direction would be great!
|
|
|
|
|
Didn't you post this same question two days ago?
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
no my last question was using xpath, and not making any progress....
I guess I will stop posting on code project...
I'm not asking someone to write this for me, I just have something new and is not working was trying to get someone to help point out what i am doing wrong so i can move forward. sorry for reposting a different but similar question.
|
|
|
|
|
No, it is just working with those tools is just an absolute PITA and to help most of us would have to paste it into a project and fiddle unless the error just jumps out at us. I usually just use xsd.exe to create a class from the XML file and then serialize into the class rather than xpath since it is lazier and easier in .NET.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
i've never used xsd.exe before this project but when i tried to create my own xsd files from the xml it complained about to many nested tables. when i found the MS xsd files i tried to create classes but it is saying something about undefined complexType.
if there is a way I can use the MS xsd files then great if not i need to figure out how to parse this xml file the hard way and i know it is going to be a PITA.
|
|
|
|
|
Hi again,
The xml was missing some end tags so I added them to test this case. When I added a name alias on xmlns attributes it began to work. Here's the code I used. Note the aliases!
string testText = "<?xml version=\"1.0\" encoding=\"utf-16\" ?> <GPO xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:<big>Alias1</big>=\"http://www.microsoft.com/GroupPolicy/Settings\"> <Identifier> <Identifier xmlns:<big>Alias2</big>=\"http://www.microsoft.com/GroupPolicy/Types\">{89AEAFFE-E1F8-4786-8AF7-6BE2D991625E}</Identifier></Identifier></GPO>";<br />
<br />
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();<br />
xml.LoadXml(testText); <br />
System.Xml.XmlNode xmln = xml.SelectSingleNode("/GPO/Identifier/Identifier");<br />
string Identifier = xmln.InnerText.ToString();
Hope this helps you forward,
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
thanks for the tip but the xml code i don't want to change it is an export that i want to import to a database
|
|
|
|
|
|
XmlNode root = xmlDocument.DocumentElement;
for (int i = 0; i < root.ChildNodes.Count; i++)
{
XmlNode node = root.ChildNodes[i];
if (node.Name == "NAME")
{
}
}
|
|
|
|
|
add http://www.microsoft.com/GroupPolicy/Settings to a new xml namespace manager and use it with your node select. Something like:
XmlNamespaceManager NSM = new XmlNamespaceManager(YOURXMLDOCOBJINSTANCE.NameTable);
NSM.AddNamespace("some_random_name_like_abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode whateverNode = YOURXMLDOCOBJINSTANCE.SelectSingleNode("//some_random_name_like_abcd:WhateverElement", NSM);
XPath will generally not work without specifying the namespace, when a namespace is defined.
|
|
|
|
|
thanks, i just tried this and making some progress now
here is what i have to get the text of the whole node and the first child
XmlDocument xml = new XmlDocument();
xml.Load(str);
XmlNamespaceManager NSM = new XmlNamespaceManager(xml.NameTable);
NSM.AddNamespace("abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode xmln = xml.SelectSingleNode("//abcd:Identifier", NSM);
if (xmln.HasChildNodes == true)
{
if (xmln.FirstChild.Name == "Identifier")
{
this.textBox2.Text = xmln.FirstChild.InnerText.ToString();
}
}
this.textBox1.Text = xmln.InnerText.ToString();
is there a better way to do this or should i get coding?
and thanks to everyone!!!
modified on Thursday, November 13, 2008 4:15 PM
|
|
|
|
|
rather use /abcd:Identifier/abcd:Identifier to get only the child nodes labeled "Identifier" of the root "Identifier" node. Use the full power of XPath if you went that way ... w3 has a great tutorial on how to use them "productive" ... http://www.w3schools.com/XPath/xpath_syntax.asp[^]
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
thanks for the link it has been helpful, I have another question
here is the xml i am trying to query
<GPO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.microsoft.com/GroupPolicy/Settings">
...
<User>
<ExtensionData>
<Extension xmlns:q1="http://www.microsoft.com/GroupPolicy/Settings/FolderRedirection" xsi:type="q1:FolderRedirectionSettings">
.....settings I need to read are child nodes here.....
</Extension>
<Name>Folder Redirection</Name>
</ExtensionData>
<ExtensionData>
<Extension xmlns:q2="http://www.microsoft.com/GroupPolicy/Settings/Registry" xsi:type="q2:RegistrySettings">
.....settings I need to read are child nodes here.....
</Extension>
<Name>Registry</Name>
</ExtensionData>
</User>
</GPO>
Is there a way i can query the xsi:type value?
if not I can query the name but not sure what the best way to jump up to the settings to read them.
this xml file does not always have the same <ExtensionData> entries so i am checking for all possible cases
|
|
|
|
|
i figured out how to do this below is the code i used, could be cleaner if this was the only thing i was checking in the User node
XmlDocument xml = new XmlDocument();
xml.Load(str);
XmlNamespaceManager NSM = new XmlNamespaceManager(xml.NameTable);
NSM.AddNamespace("abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode xmln6 = xml.SelectSingleNode("//abcd:User", NSM);
for (int i = 0; i < xmln6.ChildNodes.Count; i++)
{
XmlNode Childnode = xmln6.ChildNodes[i];
if (Childnode.Name == "ExtensionData")
{
string ExtDataTest = Childnode.ChildNodes[0].Attributes[1].Value.ToString();
string test = ExtDataTest.Substring(3, ExtDataTest.Length - 3)
}
}
|
|
|
|
|
i have the following code that is suppose to fill a datagrid. the code works fine when queried in the database but when used in the application no results are return. please help!!!!
this is the code i used....
private void cmdCompare_Click(object sender, EventArgs e)
{
string sqlquery;
sqlquery = "select * from " + Table1 + " where not exists ( select * from " + Table2 + " where " + txt_comkey_tbl1.Text + " = " + txt_comkey_tbl2.Text + ")";
OpenDb();
dbCmd = new OleDbCommand();
dbCmd.Connection = dbConn;
dbCmd.CommandText = sqlquery;
dbCmd.CommandType = CommandType.Text;
dbReader = dbCmd.ExecuteReader();
int intSkip = 0, i = 0;
ds = new DataSet();
dbtable = ds.Tables.Add(sqlquery);
for (i = 0; i < dbReader.FieldCount; i++)
dbtable.Columns.Add(dbReader.GetName(i), dbReader.GetFieldType(i));
int intIdx = 0;
while (dbReader.Read())
{
if (intIdx >= intSkip)
{
DataRow r = dbtable.NewRow();
// Assign DataReader values to DataRow.
for (i = 0; i < dbReader.FieldCount; i++)
r[i] = dbReader[i];
dbtable.Rows.Add(r);
}
intIdx++;
}
dgTblDiff.DataSource = ds.Tables[sqlquery].DefaultView;
dbReader.Close();
}
|
|
|
|
|
Use the data adapter to fill a dataset and not a datareader.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
1. Use parametrized queries instead of string concatenation. Parametrized Queries VS String Concatenation[^]
2. If you are filling DataTable why aren't you using DataAdapter instead of manually looping through datareader?
3. Ensure that the connection is initialized and don't leave it open when you no longer need it.
|
|
|
|
|
Nothing jumps out at me; I just wouldn't bother with the DataSet.
Have you stepped through it in the debugger?
And what's the purpose of the intSkip ?
|
|
|
|
|
Hi,
First of all, is there a way to get list of all Web Sites from IIS?
Secondly, how can I get information such as Port, IP Address, etc., about the Web Sites?
Last, can all of this be done in c#?
Any help on this would be appreciated.
Thanks,
Prateek
|
|
|
|