| Jerry Dausman's profileThere's an answer to you...BlogLists | Help |
|
|
August 22 .NET Language ChoicesHow many .NET languages are there? That question came up during my ms2373 class yesterday. The answer is ... lots, espcially if you count the several variations of many of the languages. Did you know that there are about 11 variations or variants of the C# language out there? (Don't ask me why!) If you want to count them for yourself, and track the additions, you can look at a couple of good sources. First is Brian Ritchie's .NET Development site at http://www.dotnetpowered.com/languages.aspx. Brian is kind enough to list the URLs to his sources. Second is http://www.dotnetlanguages.net/DNL/Resources.aspx on the .NET Languages blog.
July 13 Hashtable Internal OrderA question came up in class a few weeks ago (just after returning from TechEd 2006 Boston). The question had to do with Collections in .NET. All collection types (in System.Collections) offer some type of .Sort method ... except the Hashtable. So does the Hashtable automatically sort the items when you add them? Actually, no! OK, does it at least save them in the order you entered them? No again! I ran the code below to demonstrate:
namespace HashtableOrder
{ class Class1 { [STAThread] static void Main(string[] args) { // create the worlds most sophisticated hashtable Hashtable alpha = new Hashtable(); // add items marvelous items
alpha.Add("A", "99"); alpha.Add("B", "22"); alpha.Add("C", "88"); alpha.Add("D", "33"); alpha.Add("E", "77"); // iterate through, in Key (internal hashtable) order foreach (string letter in alpha.Keys) { Console.WriteLine(letter +" "+ alpha[letter]); } // wait a sec so we can read output Console.Read(); } } } And the output I received was ...
I used C# because VB.NET doesn't have a foreach loop. I would have used a For ... Next loop in VB.NET, but the Hashtable's Keys collection doesn't have an indexer (i.e., you can't reference it with Keys(i) syntax).
So how do we get a useable sort routine from a hashtable? Create a "super" hastable that inherits from a regular hashtable, and add your own sort method! (Ouch! Not an easy answer!)
December 08 ADOX and Access System TablesCan you believe it? It's been over a month since I've entered anything into the blog! Well, hold on to your hats ... here I go!
ADOX and Schemas
If you are familiar with SQL Server, you know that the system tables can provide you with lots of important information. What many programmers don't realize is that Access (even going back to Access version 2) has system tables. The system tables in Access all begin with the prefix 'MSys'. The basic system tables (found in Access 97) are: MSysAccessObjects, MSysACEs, MSysModules, MSysModules2, MSysObjects, MSysQueries and MSysRelationships.
How do I know this? I've used ADOX to look at the tables. I first used ADOX about 8 years ago. The company I worked at then installed accounting systems. I did a lot of custom add-ons, and needed to know of any changes to the data schema. The ADOX Library consists of classes that eXtend regular ADO, and let you look at schema details. The heirarchy of the classes is: catalog to databases collection to database to tables collection to table to columns collection to column. At each class level you have a number of properties you can read. Once you establish an ADO connection, you create a catalog object through the connenction. From there it's simply a matter of reading collections and objects in the collections. ADOX will give you the entire schema down to column properties.
Access System Tables
If you write a program that establishes an ADO connection to an Access 97 file, create a catalog object on the Access 97 file, you can actually skip the database level. Because the Access file is the only database, you don't get a databases collection in the catalog object: you get a tables collection. Iterating through the tables collection in my little VB6 program gave me the following information:
Note: I don't have to specify a SQL statement that names any objects in the database. That's a big plus, because if I don't know any objects, only how to connect to the database, this technique will at least get me a starting point. In my next blog on this topic I will show you some column detail information, and the code to get it.
October 10 SQL Two-for-OneIf you've been using SQL statements for a long time you know that you can send two statements together by simply putting a semi-colon (";") between them. Here's an example:
SELECT * FROM Customers; SELECT * FROM Orders
What happens if you load the above SQL text into the CommandText property of a data adapter's SelectCommand? If you run the following code you will get two Tables entered into your dataset.
Dim ds as new DataSet
Dim strConnectionString as string
strConnectionString = "Data Source=(local);"
strConnectionString += "Initial Catalog=Northwind;"
strConnectionString += "Integrated Security=true"
Dim conn as new SqlConnection(strConnectionString)
Dim strSQL as string
strSQL = "SELECT * FROM Customers; SELECT * FROM Orders"
Dim daInfo as new SqlDataAdapter(strSQL, conn)
daInfo.Fill(ds)
Question: what happens if you change the last line to load the data into a named table? In other words, change the last line to look like the following:
daInfo.Fill(ds, "Customers")
In last weeks ms2310 course we were all curious ... so we tried it. You get the Customers table, named, and a second table with the Orders information, unnamed. Interesting: two for the price of one!
October 07 Hacking the Templates, Part TwoLast entry I told you how to change the default project setup templates. This entry I will give you some specifics on how I set up the Web Application Project template for VB.NET, and how I changed the Add Item ... Add Web Page template.
First, I navigated to the C:\Program Files\Microsoft Visual Studio .NET 2003\VB7\VBWizards folder. This folder has subfolders for all the project types, as well as for each type of file you can add to any project. Next I navigated to the \WebApplication folder. This folder has two subfolders: \Scripts and \Templates. Inside these folders there is only one subfolder, the \1033 folder. The \1033 folders are where the files are that you want to change. In your ..\WebApplication\Templates\1033 folder you will find the following files: AssemblyInfo.vb, Global.asax, Styles.css, web.config, WebApplication.vbproj, and WebForm.aspx. These are the starter files for every web application project. Now the two things that bug me most about the default web application
projects are that: 1) grid layout is the default for every web page (I greatly prefer flow layout), and 2) the starting page is always WebForm1.aspx (I prefer Default.aspx). If you open up the WebForm.aspx file in an editor (I used Notepad) you will notice that the body element looks like this: <body ms_positioning="GridLayout>. If you simply take out the ms_positioning attribute (and its value) and save the WebForm.aspx file, your starting web page will appear in flow layout (the default).
What about subsequent web pages that you add to the project? These are not found in the ..\WebApplication\Templates\1033 folder. To change these you need to navigate to the ..\WebForm\Templates\1033 folder, and make the same change in the WebForm.aspx file found there.
Now, how about changing the project to have the first web page be called Default.aspx, and have that page as the starting page? This is a little more complicated. To accomplish this we need to edit the JScript file (default.js) found in the ..\WebApplication\Scripts\1033 folder. When you open this script you will note that there are pairs of lines that first, set the strTemplateFile variable to one of the files in the ..\WebApplication\Templates\1033 folder, and then adds (and copies) that file to the project. The file is added to the project by using the AddFileToVSProject() function. To make your first web form "default.aspx" simply find the line that does the add-copy of WebForm.aspx, and change the first passed parameter to "default.aspx". Your line of code will look like this:
item = AddFileToVSProject("default.aspx", project, project.ProjectItems, strTemplateFile, false);
To make sure the default.aspx page is the new startup page I have to find the following line in the JScript file:
configs.item().Properties("StartPage").Value = "WebForm1.aspx";
and change value property to "default.aspx" so the line looks like this:
configs.item().Properties("StartPage").Value = "default.aspx";
Just for fun I created a new web page, Jerry.html, in the ..\Templates\1033 folder. To add that file to all my new web application projects I simply added two new lines to the JScript: strTemplateFile = strTemplatePath + "\\Jerry.html";
item = AddFileToVSProject("Jerry.html", project, project.ProjectItems, strTemplateFile, false); Now I've set up my Web Application projects the way I like them. No more messing around with WebForm1.aspx and project properties at the start of every application.
October 04 Hacking the TemplatesDo you get tired of changing your web project to use only flow layout? Do you wish your windows forms always had an Exit button on them as soon as they are created? Well, what are you waiting for! Go hack your Visual Studio templates. How you may ask? (Good question, my ms2310 students just asked me that question today!) Well, here's how...
First, you need to find the templates. Look at the folders under C:\Program Files\Microsoft Visual Studio .NET 2003\ . On my machine there are three that look like language folders. They are: \VB7, \VC#, and \VC7, corresponding to Visual Basic.NET, Visual C# and Visual C.NET.
Second, taking the \VB7 folder as an example, we open it to find a \VBWizards folder. Looking at the \VBWizards folder we see subfolders that are named like 1) projects that we can create, and 2) items that we can add to our projects. Under each of these folders we will find a \Scripts\1033 folder and a \Templates\1033 folder. Those two subfolders are where the real fun lies.
If you look in the \Templates\1033 folder you will find the template items for adding the particular project or project item. If you were to change the code of one of those items, when you added that particular item in the Visual Studio design environment, you would see the changed code. (NOTE: Microsoft and myself accept no responsibility if you totally screw up and wreck your Visual Studio installation! Hack at your own risk!)
On my next posting I will show how I changed the standard WebApplication template to automatically start a project for me the way I like.
September 07 Students: 101 Free Code Samples!Can't remember something from one of my classes? (OK, so I bored you!) Well, you can always email me ... or maybe a code library of useful routines and methods would help. Microsoft has put together a free code library with 101 samples of code in both C# and VB.NET. The code samples cover areas like "syntax, data access, Windows Forms, Web development and Web services, XML, security, the .NET Framework, file system and file I/O, interop and migration issues, COM+, ADO.NET, and advanced topics including graphics with GDI+, remoting, serialization, MSMQ, and Windows services." Check it out! August 25 ADOX and .NET"I have been looking for ADOX (Active-X Data Objects eXtended) type object in .NET ever since I received my Beta 2 copy of Visual Studio .NET at TechEd 2001 in Atlanta. Guess what? There's no ADOX in .NET 2.0." ~ Jerry Dausman
What is ADOX and why is it important?
In my previous life as a consultant I dealt with a lot of accounting systems. Some of these systems allowed customization of the database, i.e., you were allowed to add fields to the important records like general ledger accounts, vendors, customers, invoices, and employees. I was often hired to create custom reports for these clients ... but when I asked for the custom field information (field name, data type, length, etc.) they couldn't always tell me. How can I report on a field if I don't know its name? How do I solve that problem? Simple, ADOX.
ADOX stands for ActiveX Data Objects eXtended. It includes objects to let you read and manipulate databases. All I need is a connection to a database and I can read the metadata. Usually someone asks me "If you can connect to the database, why don't you just read the metadata in the system tables?" Well, what if I don't know what the metadata table names are? All I had was an ODBC driver, a user name and a password. ADOX still gave me the information that I needed.
How does ADOX Work?
Once you have a connection to the server in question you create the first ADOX object, a Catalog object. A catalog object represents the information structure of a database. Catalogs have a collection of tables. You then create your second ADOX object, a table object, from one of the items in the tables collection. Besides tables there are collections of views, users, and procedures. Every table has a collection of columns, and columns have properties like names, data types, length, nullability, etc. In other words, you've got the whole schema information you need to work with the database, all from one connection and ADOX objects.
A simplified version of the ADOX object model is shown in Figure 1 below. You can find this information at ADOX API Reference.
![]() Figure 1: The ADOX Object Model (simplified).
What Next?
Over the next week or two I intend to reproduce the elements of the program I used to run to give me the schema with just a connection to the database and ADOX objects. Since there is no ADOX.NET I will use the ADOX unmanaged objects in C# .NET code. In the meantime you can check out the ADOX API Reference to look at the full information on ADOX.
August 20 VS 2005 Express Editions Will ExpireVS 2005 Express Editions will cease to function on 5/1/2006.
This evening I decided I would actually skim the End-User License Agreement before
installing Microsoft Visual Web Developer 2005 Express Beta 2. For those of you who
don't read EULAs, please note that the Beta 2 software will "cease functioning after a
certain period." Here's some of the actual text ...
Surprise! August 18 Trouble with Visio Installation?I had a problem a while back that I didn't bother to research (too many other things to do). The Problem: when you try to install Visio 2005 Beta you get an error that says you have to install Visual Studio 2005 Beta first. But I already had Visual Studio 2005 Beta installed! Ouch. Well, my friend Karla, once again, pointed me to an answer. (She should write my blog ... or maybe you should read hers!) The answer can be found at wugnet.com.
Thanks to Wugnet, Karla Carter and her friend Matthew Roche for tipping me on this. |
|
|