Code Comments
Programming Forum and web based access to our favorite programming groups.On Feb 2, 1:42 am, LX-i <lxi0...@netscape.net> wrote:
> Pete Dashwood wrote:
>
>
> I found that. (BTW, that's just another plus of the IDE - the F1 help
> is really helpful!)
>
>
>
> Must be that managed vs. unmanaged stuff... I can assign '0' to a char
> variable. I believe you - I wonder what the difference is?
>
>
> OK - here's what I've got for one of the methods. I'm not sure that
> this looks right...
>
> protected DataSet itemInfo = new DataSet();
> ...
> // Establish the element for this class instance
> public void retrieveElementInfo(String reiElementId)
> {
> // Retrieve the information about the passed program
> String sql = "SELECT * "
> + "FROM active_elements "
> + "WHERE element_id = '" + reiElementId.Trim() + "'";
> SqlDataAdapter da = new SqlDataAdapter(sql, dbConn);
> da.Fill(itemInfo);
>
> if (itemInfo.Tables.Count > 0)
> {
> elementType =
> itemInfo.Tables[0].Rows[0]["element_type"].ToString().ToCharArray()[0];
> elementSubType =
> itemInfo.Tables[0].Rows[0]["element_subtype"].ToString().Trim();
> fileName =
> itemInfo.Tables[0].Rows[0]["server_name"].ToString().Trim();
> elementId = reiElementId.Trim();
> }
> }
>
> (We have to trim the stuff coming out of the database because it's
> defined as char instead of varchar...)
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
> ~ / \ / ~ Live from Montgomery, AL! ~
> ~ / \/ o ~ ~
> ~ / /\ - | ~ daniel@thebelowdomain ~
> ~ _____ / \ | ~ http://www.djs-consulting.com ~
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> ~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
> ~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
> ~ h---- r+++ z++++ ~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
>
> "Who is more irrational? A man who believes in a God he doesn't see, or
> a man who's offended by a God he doesn't believe in?" - Brad Stine
Quick suggestion about your COBOL keywords.... instead of using an
XML file, or raw array, you'll get much better (near constant time)
lookup performance if you use a single in memory HashTable collection.
Hashtables use two objects, one is a 'key' and the other a 'value'.
Unfortunately the c# library doesn't have a Java HashSet, which has
the same behaviour as hastables, but is for storing keys only.
// Create a new hash table.
Hashtable cobolKeywords = new Hashtable();
// Add some elements to the hash table.
// hashtable does not allow
// duplicate keys, but values can be duplicates.
cobolKeywords.Add("ACCEPT", "ACCEPT ");
cobolKeywords.Add("ACCESS", "ACCESS");
cobolKeywords.Add("ACQUIRE", "ACQUIRE");
cobolKeywords.Add("ADD", "ADD");
..
// The Item property is the default property, so you
// can omit its name when accessing elements.
Console.WriteLine("The value for Add = ", cobolKeywords["ADD"] );
// ContainsKey can be used to test keys before inserting them.
if (! cobolKeywords.ContainsKey("BEFORE"))
{
cobolKeywords.Add("BEFORE", "BEFORE");
Console.WriteLine("Value added for key = \"ht\": {0}",
cobolKeywords["ht"]);
}
// When you use foreach to enumerate hash table elements,
// the elements are retrieved as KeyValuePair objects.
foreach( DictionaryEntry de in cobolKeywords)
{
Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
// To get the values alone, use the Values property.
ICollection valueColl = cobolKeywords.Values;
// The elements of the ValueCollection are strongly typed
// with the type that was specified for hash table values.
foreach( string s in valueColl )
{
Console.WriteLine("Value = {0}", s);
}
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.