Here's the problem: I'm trying to learn multi-tier design so I've been writing a little app to teach myself. I have a normalised SQLServer database which contains my music collection. The DB schema is here[^].
So, I used LLBLGen[^] to generate a C# class for each of my table entities and that works great. There are SelectOne() and SelectAll() methods on each of my entities which allow you to select one record or the whole table.
My question is: how do I join the tables together? And how do I search them? I tried asking on the asp.net forums but they just suggested buying a OR mapper tool.
I know how to do the JOIN in sql, that's not the problem. The problem is that from a design point of view each table is a separate C# class upon which I call the CRUD methods (album.Delete(), album.SelectOne() etc). What I need to know is what is the best way of joining the tables under this scenario?
I've been think of defining views for each JOIN which I require and then generating classes for each of those but I'm not convinced it is the best way to go about it.
I need to load a datagrid on a tabpage then if a user moves form tab to tab i want to retain the values they may have added but as there is no Load event for a tabpage im stuck, the enter event is no good as it would reset the datagrid values back to defauls? So when the tabpage loads i want to display default values, then if the user alters them and move yto another page and back again the values remain. No update to the database have been executed.
I am applying 2 different grid styles to the same datagrid. When I apply first style to the grid it gets applied to the grid, but when i apply the second style, it does not get applied. I am clearing the grid style before applying the new style.
Can anybody tell me what is the reason for this and what is that I am missing??
If the DataGridTableStyle.MappingName is different for both (and it must match up with the data source, such as a DataTable, array, or an IList implementation's class name), then you don't need to clear them. That's why the DataGrid.TableStyles property is a collection property. So long as the styles handle different data sources, it's not a problem to keep both in there. In fact, I'm pretty sure you're using different MappingNames since the Add method checks for duplicates and throws an exception in such a case. Just keep both styles in the collection.
When you're applying a style, you must re-bind the data source. The data source is "stylized" during binding.
I have an XML file with which has elements and each element has one or more attribute. I can read the element fine, but I am no able to read each attribute separately as my attributes are defined like..
How are you reading in the XML file? If you use an XmlTextReader, for example, there is plenty of ways to access both elements and attributes, as well as processing instructions, comments, etc. If you're using an XmlDocument along with the rest of the XML DOM classes, then there are ways to access attributes, elements, processing insturctions, etc., as well. Read the documentation for the class(es) you're using in the .NET Framework SDK.
Otherwise, please be more specific about why you can't seem to read attributes and maybe we can help.
Yes I am using the XmlTextReader. I have a file like
<?xml version="1.0" ?>
<!-- This file represents a fragment of a book store inventory database
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
I am using the ReadString funcyion to read attributes like
book genre philosophy publicastiondate 1991 etc.. but.. I can read only one string.. like only philosophy, not the reat..
I want to read each of the attributes saparately.
You should be using XML-specific methods, like GetAttribute, MoveToAttribute, or ReadAttributeValue. The idea about the XmlTextReader is forward-only reading. You move from element to element and attribute to attribute. If you treat everything as a string, of course you will not get what you want; you may as well not even use XML if you treat the document as a simple text file.
You really should read about the class members on the XmlTextReader[^].
private void AddWithChildren(XmlNode xnod, Int32 intLevel)
//Adds a node to the ListBox, togather with its children.
//intLevel controls the depth of indenting
String strIndent = new string(' ',2 * intLevel);
//Get the value of the node (if any)
string strValue = (string) xnod.Value;
if(strValue != null)
strValue = " : " + strValue;
//Add the node details to the ListBox
Console.WriteLine(strIndent + xnod.Name + strValue);
//For an element node, retrive the attributes
if (xnod.NodeType == XmlNodeType.Element)
XmlNamedNodeMap mapAttributes = xnod.Attributes;
//Add the attributes to the ListBox
foreach(XmlNode xnodAttribute in mapAttributes)
Console.WriteLine(strIndent + " " + xnodAttribute.Name +
" : " + xnodAttribute.Value);
//If there are any child node, call this procedrue recursively
xnodWorking = xnod.FirstChild;
while (xnodWorking != null)
AddWithChildren(xnodWorking, intLevel +1);
xnodWorking = xnodWorking.NextSibling;
It workes fine but I thought it would be a little easier to get the attributes.. mainly those which are present in the same line as the element tag like
<person fname=nnn lname=hhh>
Is there an easier way...
You don't read lines in XML, you move from element to element, and attribute to attribute.
Read the class documentation for the XmlTextReader in the .NET Framework SDK. There are plenty of examples there as well. It is very easy, but you don't treat XML as a plain text file, i.e. you don't read lines.
There is no easier way, man! Seriously, read the documentation for classes in the System.Xml namespace in the .NET Framework SDK. XML is easy to work with, one reason it's so popular. There's lots of examples in that documentation, like for the XmlTextReader that you'll probably want.
There's two ways of reading XML: parsing the DOM or parsing the document itself (SAX; basically). You could load an XML document completely into memory using the XmlDocument and use XPath (via SelectNodes or an XPathNavigator, which is pretty fast) to get what you need. This is good for smaller documents.
For larger documents you don't want to load the whole thing into memory, so you use SAX, which is an event-driven way to parse the document. This isn't exactly what using an XmlTextReader is, but it is a forward-only way of reading XML documents. While it isn't event driven, it is operation driven (basically the converse of SAX).
So, if you're document is small and you want to extract, for example, the language that is the default language, do something like this:
I think I'll use the XmlTextreader. I can navigate throught the nodes properly with the function I have (given up there^) but do I have to use a level variable to go to each attribute and next, Isn't there an attribute reader?? which can go without bieng followed? (by level)
See the XmlTextReader.MoveToNextAttribute, which should stick out like a sore thumb if you read the class documentation for XmlTextReader. There's simply no reason not to read the class documentation, especially for those classes you use in your code.
Thanx for the link eggie, but I cannot cache the win media 9 videos, I have a pretty slow Internet speed, & I can't connect each time I have to view them.
But anyways... that reading Xml files video was good. thanx