ASP.net Group by Multiple Columns on Datatable

6. October 2010

I have seen this request a lot on the web and I have yet to see an answer for VB.Net. The answers these people receive amount to "Why" or "You can't", in some cases some other BS code that is not what was asked for. Some instances I found a C# snippet that might have solved it, however I do not do C# and needed a VB.Net solution.

My question is: Why not simply provide a sample of the requested code if you are going to bother to reply to the question? Otherwise why not simply say you are too damn lazy to work it out? If people ask the question it means they have a need for the answer, some may be able to stray away from what they initially wanted, but not everyone can. So why give them a BS answer? Most annoying.

You can Group By on a Datatable using multiple columns, however you have to code it and it is not a part of the Datatable. Thus all the questions on how to do it and the purpose of this post.

At any rate here is my solution, it may not be the best nor very elegant, but it answers the friggin question and it worked to serve my purpose without using the BS most people received as an answer.

Groups on One column by default and allows up to 5 columns. It does add a Count Column as a bonus.
You pick and modify as needed.

Inputs:

myDataTable = Your Datatable 
5 = Number of fields to use as Integer
strx(x) = Column Names as string

The following spits it out into an HTML Table.

Response.Write(Grouping2(myDataTable, 5, strx(0), strx(1), strx(2), strx(3), strx(4)))

My need was a dynamic selection of Columns up to 5. After some research and head scratching I came up with this:

    Function Grouping(ByVal dt As DataTable, ByVal Opts As Integer, ByVal str1 As String, Optional ByVal str2 As String = "", _
                  Optional ByVal str3 As String = "", Optional ByVal str4 As String = "", Optional ByVal str5 As String = "") As String
        'Row Count
        Dim i As Integer = 0
        'Iteration Count
        Dim x As Integer = 0
        'Columns
        Dim CurColumn1 As String = ""
        Dim CurColumn2 As String = ""
        Dim CurColumn3 As String = ""
        Dim CurColumn4 As String = ""
        Dim CurColumn5 As String = ""


        Dim result As New StringBuilder()
        Dim CurString As String = ""
        Dim dv As New DataView(dt)
        Select Case Opts

            Case 0
                CurString = str1 & " ASC"
            Case 1
                CurString = str1 & " ASC" & "," & str2 & " ASC"
            Case 2
                CurString = str1 & " ASC" & "," & str2 & " ASC" & "," & str3 & " ASC"
            Case 3
                CurString = str1 & " ASC" & "," & str2 & " ASC" & "," & str3 & " ASC" & "," & str4 & " ASC"
            Case 4
                CurString = str1 & " ASC" & "," & str2 & " ASC" & "," & str3 & " ASC" & "," & str4 & " ASC" & "," & str5 & " ASC"

        End Select

        dv.Sort = CurString

        Dim r As DataRowCollection = dv.ToTable.Rows

        CurString = ""
        ' Set Field names to append given Opts Integer
        result.AppendLine("<table cellspacing='0' rules='all' border='1' style='font-size:12pt;border-collapse:collapse;'>")

        Select Case Opts
            Case 0
                CurString = str1
                result.AppendFormat("<tr style='background-color:LightGrey;font-weight:bold;'><td>{0}</td>", CurString).AppendLine()

                CurString = "COUNT"
                result.AppendFormat("<td>{0}</td></tr>", CurString).AppendLine()


            Case 1

                CurString = str1
                result.AppendFormat("<tr style='background-color:LightGrey;font-weight:bold;'><td>{0}</td>", CurString).AppendLine()

                CurString = str2
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = "COUNT"
                result.AppendFormat("<td>{0}</td></tr>", CurString).AppendLine()


            Case 2

                CurString = str1
                result.AppendFormat("<tr style='background-color:LightGrey;font-weight:bold;'><td>{0}</td>", CurString).AppendLine()

                CurString = str2
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = str3
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = "COUNT"
                result.AppendFormat("<td>{0}</td></tr>", CurString).AppendLine()

            Case 3
  
                CurString = str1
                result.AppendFormat("<tr style='background-color:LightGrey;font-weight:bold;'><td>{0}</td>", CurString).AppendLine()

                CurString = str2
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = str3
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = str4
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = "COUNT"
                result.AppendFormat("<td>{0}</td></tr>", CurString).AppendLine()

            Case 4
         
                CurString = str1
                result.AppendFormat("<tr style='background-color:LightGrey;font-weight:bold;'><td>{0}</td>", CurString).AppendLine()

                CurString = str2
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = str3
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = str4
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = str5
                result.AppendFormat("<td>{0}</td>", CurString).AppendLine()

                CurString = "COUNT"
                result.AppendFormat("<td>{0}</td></tr>", CurString).AppendLine()

        End Select
        'Append Field names to the result



        'result.AppendFormat("{0}", vbCrLf).AppendLine()
        CurString = ""

        While (i < r.Count)
            'Default Column
            CurColumn1 = r(i)(str1)
            'x records the Number of Occurences
            'Zero out x prior to the next iteration
            x = 0

            'Opts is a value 0-4 Representing the 1 to 5 Fields for the Group By
            'Each Case performs the same function with one more column than the previous Case
            Select Case Opts
                Case 0
                    'iterate through the records with our Criteria
                    'Set Column Values (We only use the Default Column here)
                    CurColumn2 = ""
                    CurColumn3 = ""
                    CurColumn4 = ""
                    CurColumn5 = ""
                    While i < r.Count AndAlso CurColumn1 = r(i)(str1)

                        'iterate through the records
                        While i < r.Count AndAlso CurColumn1 = r(i)(str1)
                            i += 1 'Next Record
                            x += 1 'Record Count Per
                            'Set our string Value and Number of Iterations
                            CurString = "<tr><td>" & r(i - 1)(str1) & "</td><td>" & x & "</td></tr>"
                        End While

                    End While
                    'Set our string Value and Number of Iterations
                    result.AppendFormat("{0}", CurString).AppendLine()
                    result.AppendFormat("{0}", vbCrLf).AppendLine()
                Case 1
                    'iterate through the records with our Criteria
                    'Set Column Values
                    CurColumn2 = r(i)(str2)
                    CurColumn3 = ""
                    CurColumn4 = ""
                    CurColumn5 = ""
                    While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2)

                        'iterate through the records
                        While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2)
                            i += 1 'Next Record: same user, role '
                            x += 1 'Record Count Per
                        End While
                        CurString = "<tr><td>" & r(i - 1)(str1) & "</td><td>" & r(i - 1)(str2) & "</td><td>" & x & "</td></tr>"

                    End While
                    'Set our string Value and Number of Iterations
                    result.AppendFormat("{0}", CurString).AppendLine()
                    result.AppendFormat("{0}", vbCrLf).AppendLine()
                Case 2
                    'iterate through the records with our Criteria
                    'Set Column Values   
                    CurColumn2 = r(i)(str2)
                    CurColumn3 = r(i)(str3)
                    CurColumn4 = ""
                    CurColumn5 = ""
                    While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2) AndAlso CurColumn3 = r(i)(str3)

                        'iterate through the records
                        While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2) AndAlso CurColumn3 = r(i)(str3)
                            i += 1 'Next Record
                            x += 1 'Record Count Per group
                        End While

                    End While
                    'Set our string Value and Number of Iterations
                    CurString = "<tr><td>" & r(i - 1)(str1) & "</td><td>" & r(i - 1)(str2) & "</td><td>" & r(i - 1)(str3) & "</td><td>" & x & "</td></tr>"
                    result.AppendFormat("<tr><td>{0}</td></tr>", CurString).AppendLine()
                    result.AppendFormat("{0}", vbCrLf).AppendLine()
                Case 3
                    'iterate through the records with our Criteria
                    'Set Column Values
                    CurColumn2 = r(i)(str2)
                    CurColumn3 = r(i)(str3)
                    CurColumn4 = r(i)(str4)
                    CurColumn5 = ""
                    While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2) AndAlso CurColumn3 = r(i)(str3) AndAlso CurColumn4 = r(i)(str4)

                        'iterate through the records
                        While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2) AndAlso CurColumn3 = r(i)(str3) AndAlso CurColumn4 = r(i)(str4)
                            i += 1 'Next Record
                            x += 1 'Record Count Per Group
                        End While

                    End While
                    'Set our string Value and Number of Iterations
                    CurString = "<tr><td>" & r(i - 1)(str1) & "</td><td>" & r(i - 1)(str2) & "</td><td>" & r(i - 1)(str3) & "</td><td>" & r(i - 1)(str4) & "</td><td>" & x & "</td></tr>"
                    result.AppendFormat("<tr><td>{0}</td></tr>", CurString).AppendLine()
                    result.AppendFormat("{0}", vbCrLf).AppendLine()
                Case 4
                    'iterate through the records with our Criteria
                    'Set Column Values
                    CurColumn2 = r(i)(str2)
                    CurColumn3 = r(i)(str3)
                    CurColumn4 = r(i)(str4)
                    CurColumn5 = r(i)(str5)
                    While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2) AndAlso CurColumn3 = r(i)(str3) AndAlso CurColumn4 = r(i)(str4) AndAlso CurColumn5 = r(i)(str5)

                        'iterate through the records
                        While i < r.Count AndAlso CurColumn1 = r(i)(str1) AndAlso CurColumn2 = r(i)(str2) AndAlso CurColumn3 = r(i)(str3) AndAlso CurColumn4 = r(i)(str4) AndAlso CurColumn5 = r(i)(str5)
                            i += 1 'Next Record
                            x += 1 'Record Count Per Group
                        End While

                    End While
                    'Set our string Value and Number of Iterations
                    CurString = "<tr><td>" & r(i - 1)(str1) & "</td><td>" & r(i - 1)(str2) & "</td><td>" & r(i - 1)(str3) & "</td><td>" & r(i - 1)(str4) & "</td><td>" & r(i - 1)(str5) & "</td><td>" & x & "</td></tr>"
                    result.AppendFormat("<tr><td>{0}</td></tr>", CurString).AppendLine()
                    result.AppendFormat("{0}", vbCrLf).AppendLine()
            End Select


            ' result.AppendFormat("{0}", CurString).AppendLine()

        End While
        ' Response.Write(Opts & "<BR>")

        ' Response.Write("<br><br>grouping: " & i & " " & result.ToString)

        result.AppendLine("</table>").AppendLine()

        Grouping = result.ToString

        CurString = ""
        CurColumn1 = ""
        CurColumn2 = ""
        CurColumn3 = ""
        CurColumn4 = ""
        CurColumn5 = ""

    End Function

Reference , , ,

End the Fed (End The Federal Reserve)

18. June 2009

You must first realize that the Federal Reserve is neither Federal nor a Reserve. It is a cartel of privately owned banks. Since its inception it has caused the dollar to decrease in value by 96%. It causes inflation with every dollar it prints. These new dollars increase the money supply and as they are created from debt they offer no new value on their own. This in turn decreases the value of your money and causes the cost of living to go up. This is the hidden tax my friends. The bailouts are funded by money printed by the Fed. You know they had no money on hand to fund the Bailouts. Inflation comes next. You hear about elected officials speaking of controlling inflation from time to time? All they have to do is End the Fed and create money backed by gold or silver as JFK tried to do and did do for a limited time until he was murdered.

With that said I offer the following Quotes from a few men from our history.

“All the perplexities, confusion and distress in America arise, not from defects in their Constitution or Confederation, not from want of honor or virtue, so much as from the downright ignorance of the nature of coin, credit and circulation.” - John Adams.

"If the American people ever allow private banks to control the issue of their currency, first by inflation, then by deflation, the banks...will deprive the people of all property until their children wake up homeless on the continent their fathers conquered...The issuing power should be taken from the banks and restored to the people, to whom it properly belongs."  - Thomas Jefferson
 

"History records that the money changers have used every form of abuse, intrigue, deceit, and violent means possible to maintain their control over governments by controlling money and its issuance." - James Madison  

"The bold efforts that the present bank has made to control the government, the distress it has wantonly caused, are but premonitions of the fate which awaits the American people should they be deluded into a perpetuation of this institution. If the people only understood the rank injustice of the money and banking system there would be a revolution before morning. You are a den of vipers and thieves…If Congress has the right under the Constitution to issue paper money, it was given them to use themselves, not to be delegated to individuals or corporations." - Andrew Jackson 

"The money power preys upon the nation in times of peace and conspires against it in times of war. It is more despotic than monarchy, more insolent than autocracy, more selfish than bureaucracy. It denounces, as public enemies, all that even question its methods or throw light upon its crimes. I have two great enemies: the Southern Army in front of me and the financial institutions at the rear. The latter is my greatest foe."  - Abraham Lincoln 

"I see in the near future a crisis approaching that unnerves me and causes me to tremble for the safety of my country.  Corporations have been enthroned, an era of corruption will follow, and the money power of the country will endeavor to prolong its reign by working upon the prejudices of the people, until the wealth is aggregated in a few hands, and the republic destroyed...The government should create, issue, and circulate all the currency and credits needed to satisfy the spending power of the Government and the buying power of consumers.  By the adaptation of these principles the taxpayers will be saved immense sums of interest.  Money will cease to be the master and become the servant of humanity." - Abraham Lincoln

 

Political , , ,

Is it better to have One Table or More?

6. March 2009

In table design we often ask the above question. My answer is: Yes it is usually better to have more than one table. If you are just starting your database I would suggest the multiple table route.

Your Database may contain names, addresses, companies and Company products if so then it would be beneficial to have multiple tables. One table to contain “Names”, a Second for “Companies”, a third for “Location”, a fourth for “Products”, and a fifth that ties Companies and products together by an ID field, you might call it “Company_Production” or "Attributes". If these were under a single table with several names per company and several products per company with companies residing in multiple states you would have a monster of a table that would take forever to process and contain multitudes of redundancies. By splitting it into multiple tables you can eliminate redundancies and make it more flexible and easier to maintain.

With multiple tables you can link them all to get at all your data if desired in a single query; you could also link two or three tables in a query to see different aspects and summaries. This would likely speed up the process in larger databases with hundreds of thousands of records.

Multiple tables also allows you to easily add other tables in the same fashion if you find you need to. In MS Access this means you could, if you choose, house each table in an individual mdb file and then link to them via a master mdb file effectively expanding the file size limit in MS Access. Containing the data all in one table would require you to have one mdb file thus limiting you to that files size limit. A few million records could effectively cause you problems in a one table database. That is if you are willing to link tables in MS Access. Of course you could do the same using SQL as a back end then linking the SQL tables via ODBC into MS Access as a front end. Either way you would still be linking Tables in MS Access if you have a huge pool of data and you require MS Access as a front end.

So is it better to have One Table or More? In short, yes.

Tags:

MS Access, Reference , , , ,

Set the First Home Page in IE Internet Explorer

19. February 2009

A registry tweak, use at your own risk.

Works in IE6 and IE7. This is not tested in IE8 however I see no reason, thus far, that it won't work for IE8.

In windows you can use Regedit by clicking Start, Run and then type Regedit.
This will set the First Home Page for IE. This is the page that loads when you first start IE. This not to be confused with the Home button in IE. The home button should follow whichever Homepage you have set in IE's Internet Options. So in effect you could have two home pages. One which shows when you start IE and one which shows when you click Home. At this point it would be a good idea to print this portion and close all open windows as you should re-boot to ensure the new settings take. Also keep in mind Software that protects changes to the registry should be disabled, like Adaware Adwatch and Spybots Search & Destroy Teatimer. Remember to re-enable any software you disabled when you are finished.

It is a good idea to set a restore point in Windows XP or back up your Registry at this point. Both are beyond the scope of this post, you can Google "back up your Registry" to find the information you may need.

[HKEY_CURRENT_USER\Software\Microsoft \Internet Explorer\Main]
"First Home Page"="
http://www.google.com/"

You will need to use the Folder Icons in the left hand window and expand each folder icon until you find the "Main" folder and left click it. My own PC lacked this value.

If the String Value "First Home Page" does not exist you will have to ensure you have left clicked "Main" in the left hand side of the Registry Editor. Once this is done re-verify "First Home Page" is not present in the right hand side of the window. If "First Home Page" is not present then Rt click the right hand side of the window and then select New/String Value. This will insert a new value ready to be named, so name it "First Home Page" without the Quotes. Double click your new entry "First Home Page" and enter a new value.

As above "
http://www.google.com/" would be the First homepage URL you wish to use.
Use the above at your own risk; I am not responsible if you screw up your registry.

The folowing picture is what it should look like when you are finished:

STOP the IE7 Get it now Offer 

Note: If you wish to change your first home page then you will need to re-edit the above registry setting.

Tags: 

Reference , ,

MS Access Table Design

15. February 2009
I am going to discuss MS Access Table Design in this post it will be detailed and lengthy. We will deal with basic data; each record will contain Name and Address information. We will then walk through the process of designing the Table or Tables as the situation may require. We will touch on Field Data Types, Primary keys and Indexing and field sizes.  We could go about this in at least two ways. The first is to set up a single Table for our data in which we include the Name of the contact and their Address. A single table is simple and functional for smaller databases. The Second is to split the Names from the Addresses into two Tables each with a common field we can use to join them. Two tables will add a small level of complexity and is better for larger databases.  The actual process of creating a Table will be similar for both methods and the process is similar in MS Access 97, 2000 and 2003. MS Access 2007 has some differences however once you have the initial table in design view you can follow along. 
For a Basic Table Design with pictures see my MS Access Basic Table Design Tutorial.

 

Section One: Creating an MS Access Table

This section will have some commonalities for both the Single and the Two Table design process.

Part One: Creating the Table in MS Access

1) In an existing MS Access Database, under the Objects Menu of left hand side of the window, select Tables
2) Select Create Table in Design View
3) A new window will pop up called Table1: Table where 1 can be any number depending on current table names if any

Part Two: Creating Fields for an MS Access Table

            1) The new Table Design window will have three columns: Field Name, Data Type, Description
            2) Under Field Name you will enter the Names of the fields we want in our new Table
            3) Enter in the following Fields:
                        a) RECNUM              
                        b) CONTACT
                        c) ADDRESS
                        d) ADDR2
                        e) CITY
                        f) STATE
                        g) ZIP
                        h) PREFIX
                        i) FIRSTNAME
                        k) LASTNAME
                        l) SUFFIX
                        m) GENDER
                        n) ZIP5
            4) In the Description column you can type a description for each field
            5) Enter in the following descriptions for others who may view the Table:
                        a) RECNUM field: “Master Record Number for each contact.”
                        b) ZIP field: 9 digit zip code
                        c) ZIP5 field: 5 digit zip code 
            6) Select Data Types from the Data Type column, default is Text
            7) Change the following Data Type:
                        a) RECNUM Field: Data type Autonumber
                        b) The rest can remain as Text

Zip codes you may think should be set to Data Type Number, this is incorrect. MS Access will drop all leading Zeros for any number, at least for Versions 97-2003. As for 9 digit Zip codes you have a – and the dash makes the number a string Text data type. MS Access 2007 may have a Data Type for Zip codes however Text works just fine in either case.

At this point you may wish to set Field sizes on the bottom half of the screen named “Field Properties” on the “General” Tab find Field Size. Text fields default to 50, you can enter in the appropriate size for ZIP (Set to 10, 9 digit zip code and the -), ZIP5 (Set to 5) and so on. Be aware that if you enter data whose length is longer than the field size, via Appends, Updates or otherwise, the data will be truncated to the field size.

 

Part Three: Setting Primary Keys and Indexing in MS Access

            1) RECNUM field: Right click and select Primary Key
                       
                       
a) Note that the RECNUM field would be used to join your contacts to another table such as one called SALES
                        b) To Join fields in a Query they must be of the same Data Type (Autonumber is considered a Data Type of Number and is a Long Integer under Field Size)
                        c) You can select multiple fields as Primary Key, to do this Click one field, then hold the CTRL key and click another, while holding CTRL right click one of the fields selected and click Primary Key
                        d) Primary Keys must be Unique, meaning there can be no duplicate records within the Primary Key
                        e) Primary Keys automatically set Indexed to “Yes (No Duplicates)” attempting to change this would result in the removal of the Primary Key

            2) ZIP5, CITY, STATE, GENDER and LASTNAME fields: Left click each one   at a time
                        a) Per each field on the bottom half of the screen named “Field Properties”  on the “General” Tab find “Indexed” its default is No
                        b) Change No to “Yes (Duplicates OK)” by clicking and selecting it from the list
                        c) Fields you will be searching through or using to join to other tables should be indexed to improve performance

 

At this point you can close your table. MS Access will then ask you to save if you have not already. MS Access will also ask you to set a Primary Key if you have not.

Hear the Single Table Design process ends.

 

Section Two: Creating Two Tables in MS Access to store related Data
You may want two tables in which both tables will have a field in common to tie the two together. In my case I will have one table for contacts and a second for their location.

Part One:
The same as “Section One”, “Part One process” for both tables

            1) In an existing MS Access Database, under the Objects Menu of left hand side of the window, select Tables
            2) Select Create Table in Design View 
            3) A new window will pop up called Table1: Table where 1 can be any number depending on current table names if any

Part Two:  Creating Fields for an MS Access Table

 

            1) The First table I will refer to and eventually save as New_Contacts
            2) Under Field Name you will enter the Names of the fields we want in our new Table
            3) Enter in the following Fields:
                        a) RECNUM              
                        b) CONTACT
                        c) PREFIX
                        d) FIRSTNAME
                        e) LASTNAME
                        f) SUFFIX
                        g) GENDER

Part Three: Setting Primary Keys and Indexing in MS Access

            1) RECNUM field: Right click and select Primary Key
                        a) Note that the RECNUM field would be used to join your New_Contacts table to the second table I will call LOCATION
                        b) To Join fields in a Query they must be of the same Data Type (Autonumber is considered a Data Type of Number and is a Long Integer under Field Size) both tables will include the RECNUM field
                        c) Primary Keys must be Unique, meaning there can be no duplicate records within the Primary Key

            2) GENDER and LASTNAME fields: Left click each one at a time
                        a) Per both fields on the bottom half of the screen named “Field Properties” on the “General” Tab find “Indexed” its default is No
                        b) Change No to “Yes (Duplicates OK)” by clicking and selecting it from the list
                        c) Fields you will be searching through or using to join to other tables should be indexed to improve performance Primary Keys automatically set Indexed to “Yes (No Duplicates)”

You would now want to save the New_Contacts Table. 

Part Four: The Second Table in MS Access

            1) The Second table I will refer to and eventually save as LOCATION
            2) Under Field Name you will enter the Names of the fields we want in our new Table
            3) Enter in the following Fields:
                        a) RECNUM              
                        b) ADDRESS
                        c) ADDR2
                        d) CITY
                        e) STATE
                        f) ZIP
                        g) ZIP5

Part Five: Setting Primary Keys and Indexing in MS Access

            1) RECNUM field: Right click and select Primary Key
                       a) Note that the RECNUM field would be used to join your New_Contacts table to the second table I will call LOCATION
                       b) To Join fields in a Query they must be of the same Data Type (Autonumber is considered a Data Type of Number and is a Long Integer under Field Size) both tables will include the RECNUM field
                       c) Primary Keys must be Unique, meaning there can be no duplicate records within the Primary Key

            2) CITY, STATE and ZIP5 fields: Left click each one at a time
                        a) Per both fields on the bottom half of the screen named “Field Properties” on the “General” Tab find “Indexed” its default is No
                        b) Change No to “Yes (Duplicates OK)” by clicking and selecting it from the list
                        c) Fields you will be searching through or using to join to other tables should be indexed to improve performance Primary Keys automatically set Indexed to “Yes (No Duplicates)”

You would now want to save the LOCATION Table. 
One thing to note that pertains to both methods: upon creating new fields on the bottom half of the screen named “Field Properties” on the “General” Tab find “Required”. Set this to No if you want to be able to leave fields blank when entering new data. 

You should now be done Designing your Table or Tables in MS Access and are now ready to begin entering Data.

Tags: 

MS Access, Reference , , , ,

Prevent Clicking your AdSense by Accident in ASP.NET

13. February 2009

Here is a simple ASP.NET Code Snippet that Hides your AdSense by blocking or filtering your IP.

This part you would want to place before what you want to block the IP from:

<%

string strIP = Request.UserHostAddress;

switch (strIP) {

case "IP#1 here":

Response.Write("No Ad1: " + strIP + " ");

break;

case "IP#2 here":

Response.Write("No Ad2: " + strIP + " ");

break;
default:

%>

The following you place after whatever it is you want blocked from certain IPs:

Some Code here

<%

break;

}

%> 

Tags:

Reference , ,

MS Access Group by, Count and Sum Query

9. February 2009

I posted this in a forum somewhere; I figured I would repost here with pictures.

Say you have a Table named 1A and Three Fields Named COUNTRY, COMPANY and BALANCE.
The following SQL Code Counts Each Company in each Country and Sums their Balance all in one Query:

SELECT [1A].COMPANY, [1A].COUNTRY, Sum([1A].BALANCE) AS SumOfBALANCE, Count("") AS SHOW_COUNT
FROM 1A
GROUP BY [1A].COMPANY, [1A].COUNTRY;

MS Access Count and Sum Query. 


In MS Access you can copy/paste the SQL into a Query using SQL View. You can then write over the "1A"s with your own table name.

MS Access SQL View Query. 


SQL View is very handy in Reverse as well. On Running the Query you will then Count each instance of a Company within a Country and Sum their Balances within said Countries.

To get a company’s Grand Total you would run the above as a Make Table Query and then run the Following on the New Table:
Use the Method above to paste into a new Query:

SELECT [1A].Company, Sum([1A].BALANCE) AS SumOfBALANCE
FROM 1A
GROUP BY [1A].Company;

A two step process for Totals of a Company World wide, a one step process for Totals of a Company per Country.

Tags: 

MS Access, Reference , , , , ,

Prevent Clicking your AdSense by Accident

6. February 2009

Here is a simple ASP Code Snippet that Hides your AdSense by blocking or filtering your IP.

This part you would want at the top of a page:
<%
dim blockip
 
blockip = Request.ServerVariables("REMOTE_HOST")
%>

The following you place wherever your Ads would be:

A Single IP# Version:


<%
 if blockip <> "000.000.000.000" then%>

    <div align="center">
“Your AdSense Code here.” Note: Replace the 000.000.000.000 and 111.111.111.111 with the IP# you wish to block.
    </div>
<%   
   else
   "Show Something Else."
   end if   
%>

 

A Two IP # Version:

<%
 if blockip <> "000.000.000.000" then
    if blockip <> "111.111.111.111" then %>
    
“Your AdSense Code here.” Note: Replace the 000.000.000.000 and 111.111.111.111 with the IP# you wish to block.
  
<%   
   else
      "Show Something at work."
   end if   
 else
     "Show Something at home."
 end if
%>

Tags:

Reference , ,

MS Access Tutorials, Examples and Help

4. February 2009

The following are links and descriptions of various MS Access Queries authored by me:
MS Access Tutorials For my Complete List

 

MS Access tutorials 2000, 2002, 2003, 2007:

A series of Microsoft Access Database Tutorials and Examples written by myself.


  • Left Hand Column Covers VBA



  • All tutorials created in MS Access 2003

  • Right Hand Column Covers Tables and Queries

  • MS Access Autonumber Field with VBA
    Creates an Autonumber field using VBA, Changes a current fields name, Adds a regular Text Field all in VBA on an Existing Table
    "Not Enough Space on Temporary Disk" error work around
    Makes use of a MS Access Form and Module

  • MS Access Create Table
    This tutorial walks you through the MS Access Create Table in Design View process

  •  MS Access VBA Update Field
    Using VBA to Update a Field, VBA Code to Update an existing field

  • MS Access Basic Table
    In this tutorial you will learn basic MS Access Table Design : Index, Autonumber using data type

  •  MS Access VBA Create Field
    Using VBA to create a new Field with several data types available

  • MS Access Query Builder
    A very Basic MS Access Select Query using an All Fields Wild card

  • MS Access VBA Change Field Data Type
    Using VBA to Change a Fields Data Type, VBA Code that changes a Fields data Type using ALTER Table ALTER Column

  • MS Access Query Builder 2
    MS Access Select Query using specific criteria with joins

  • MS Access VBA Check if Table Exists
    VBA Check if Table Exists, VBA Code to Check for a table

  • MS Access Query Builder 3
    Select Query using specific criteria with WildCards in MS Access

  • MS Access VBA Check if Field Exists
    VBA Check if Field Exists, VBA Code to Check for a Field in a Table

  • MS Access Append Query Tutorial
    A simple "How To" MS Access Append Query

  • MS Access VBA Delete Query
    Using VBA Delete Query, VBA Code to Delete existing records given Criteria

  • MS Access Append Query in SQL
    Shows how to view the MS Access Append Query In SQL View

  •  MS Access VBA Get All Fields
    Using VBA to Get All Fields, VBA Code that Returns all Fields Within a Table

  • MS Access Update Query Tutorial
    An MS Access Update Query that uses a Yes/No Field to select records

  • MS Access VBA Rename Field
    Using VBA to Rename a Field, VBA Code to rename existing fields

  • MS Access Insert Into or Make Table Query Tutorial
    Create a new table using the MS Access Make Table Query

  • Coming Soon!

  • MS Access Simple Primary key
    Learn how to set the MS Access Primary Key: Setting the Primary Key for one or more fields in a Table

  • Coming Soon!

  • MS Access Count Query Tutorial
    Create a new Query to "Group By" and count a with criteria in MS Access

  • Coming Soon!

  • MS Access Count Query Tutorial for a Yes/No Field
    Create a new Query to "Group By" and count a Checked Yes/No field in MS Access

  • Coming Soon!

  • MS Access Delete Query Tutorial
    A basic MS Access Delete Query using criteria


  • Tags:

    MS Access, Reference , , ,

    New Hampshire Liberty Alliance

    8. November 2008
    From New Hampshire Liberty Alliance

    "From the International Society for Individual Liberty, this 8 minute animation lays out the essence of liberty-oriented political philosophy. Whether expressed as Austrian Economics, Goldwater Conservatism, Jeffersonian Democracy, Classical Liberalism, or just libertarianism, the fundamental philosophy has been the same."
    I came accross this today and decided I should add this to my Blog. This is an organization that should be embraced and actively supported by the citizens.

    Political , ,