السبت، 22 أكتوبر 2011

Combo Box Data Binding With VB .Net

Introduction

Combo box data binding allows a combo box on a form to display a list that is external to the source of data of its form. For example, you can have a combo box that displays a fixed list of values that you create from the Items property of the combo box. For a relational database, you may want the combo box to display a list of values from a column of another table. To make this possible, you must link the combo box to the items of the other table.
To follow this example, you should have Microsoft SQL Sever 2005 and Microsoft Visual Studio 2005.
Practical Learning: Binding a Combo Box 


  1. To get the database used in this exercise start the Microsoft SQL Server Management Studio and log in to the server
  2. On the main Menu click File -> New -> Query With Current Connection
  3. To create the database, type the following:
     
    CREATE DATABASE StudentBinding;
    GO
    
    USE StudentBinding;
    GO
    CREATE TABLE Genders
    (
        GenderID int identity(1,1) PRIMARY KEY,
        Gender varchar(20)
    );
    GO
    INSERT INTO Genders(Gender) VALUES('Female');
    GO
    INSERT INTO Genders(Gender) VALUES('Male');
    GO
    INSERT INTO Genders(Gender) VALUES('Unknown');
    GO
    
    CREATE TABLE Students
    (
        StudentID int identity(1,1) PRIMARY KEY,
        FirstName varchar(20),
        LastName varchar(20) NOT NULL,
        GenderID int
    );
    GO
    INSERT INTO Students(FirstName, LastName, GenderID)
    VALUES('Helene', 'Mukoko', 1);
    GO
    INSERT INTO Students(FirstName, LastName, GenderID)
    VALUES('Gertrude', 'Wachs', 3);
    GO
    INSERT INTO Students(FirstName, LastName, GenderID)
    VALUES('Peter', 'Lansome', 2);
    GO
    INSERT INTO Students(FirstName, LastName, GenderID)
    VALUES('Paul', 'Motto', 2);
    GO
    INSERT INTO Students(FirstName, LastName, GenderID)
    VALUES('Hermine', 'Ngaleu', 1);
    GO
  4. Press F5 to execute
  5. Start Microsoft Visual Studio 2005
  6. To create a new application, on the main menu, click File -> New -> Project ...
  7. In the Projects list, select Visual C++ and, in the Templates list, click Windows Forms Application
  8. Set the Name to StudentBinder1 and click OK
  9. On the main menu, click Data -> Add New Data Source
  10. In the first page of the wizard, make sure Database is selected and click Next
  11. In the second page of the wizard, click New Connection
  12. For the server name, type (local)
  13. For the Database Name, select StudentBinding

  14. Click OK
  15. In the second page of the wizard, make sure ServerName.StudentBing.dbo is selected in the combo box and click Next
  16. In the third page of the wizard, click the Tables check (that will select both tables of our database)
  17. Set the DatasetName to dsStudents

  18. Click Finish
  19. From the Data Source window, click Students and click the arrow of its combo box to select Details
  20. Drag Students and drop it on the form
  21. Delete the GenderID textBox and customize the design of the form as you see fit
  22. On the Toolbox, in the Data section, click BindingSource and drop it on the form
  23. Change its properties as follows:
    Name: bsGenders
    DataSource: dsStudents
    DataMember: Genders
  24. Add a combo box to the form and specify its properties as follows:
     
    NameDataSourceDisplayMemberValueMemberDataBindings -> SelectedValue
    cboGendersbsGendersGenderGenderIDStudentsBindingSource - GenderID
  25. Execute the application to see the result

الأربعاء، 19 أكتوبر 2011

VB.NET Tips and Tricks-Combo/Listbox and Multiple column keys on hashtables



Combo/Listbox: ItemData and NewIndex

What kicks your butt in the beginning is simple little things. I remember when I first tried to insert items into a listbox and was hunting all over for the .AddItem method that would allow me to do so.
When I found out that the VB.NET listbox had an internal Items collection that turned the Listbox.AddItem syntax into Listbox.Items.Add syntax, I was nonplussed at first. However, as you work with more of the classes in the Framework, you begin to see the consistency that was missing in VB 6.0.
The items collection behaves the same as other collections in the framework, because they are derived from a common ancestor. Useful members like .AddRange, or .Contains are always there. And you never have to worry about using .ListCount instead of .Count (in .NET it will always be .Count) or think about whether the collection is zero or one based (always zero.)
At first I was missing two useful properties in the listbox/combobox. ItemData and NewIndex In VB 6.0 the .NewIndex property retrieves the index of the item added last. This can be done by checking the return value of the .Add method which returns the index. ItemData was useful because it could be used to save an integer value corresponding to the list item. This is handy when you have a numeric key to a column. When I realized that you could add ANY object to the Items collection, it became clear that this was a far more flexible approach and there wasn't anything lost at all in the translation ... Rather it was a .NET gain.
In order to add an object to the Listbox or combo box item collection, you must override the ToString method so that you will have a meaningful entry displayed in the list.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i As Integer = 1 To 10
            'Index will hold the index of the newly added item.
            Dim Index As Integer = ListBox1.Items.Add(New ListItem(i, String.Format("Item {0}", i)))
            Debug.WriteLine(Index)  'will print the zero based index
        Next i

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        'Cast it back to listitem class
        Dim ListItem As ListItem = DirectCast(ListBox1.SelectedItem, ListItem)
        Label1.Text = String.Format("ID={0}, Name={1}", ListItem.ID, ListItem.Name)
    End Sub
End Class


Public Class ListItem
    Private mID As Integer
    Private mName As String

#Region "Constructor(s)"
    Public Sub New(ByVal ID As Integer, ByVal Name As String)
        mID = ID
        mName = Name
    End Sub

    Public Sub New()
        'Empty default constructor
    End Sub
#End Region
#Region "Properties"

    Public Property ID() As Integer
        Get
            Return mID
        End Get
        Set(ByVal Value As Integer)
            mID = Value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return mName
        End Get
        Set(ByVal Value As String)
            mName = Value
        End Set
    End Property

    Public Overrides Function ToString() As String
        'Required so that the listbox will display the correct
        'label
        Return mName
    End Function


#End Region
End Class


Multiple column keys on hashtables

Roxio Creator  2012
The Hashtable is the class that is most like a VB 6.0 collection. It allows you to retrieve an object with a key. Sometimes you want to key a hashtable on two values rather than one. In VB 6.0 one would combine the two elements into a string and use that as a key, but that is an ugly hack.

In VB.NET, as you can assign an object to the key, it seems easy enough to create an object to store the two values and use that as the key. However, when you do this, you have to override two of the objects methods: GetHashCode and Equals. If you don't override these methods, the hashtable will not recognise your key as a unique object. Although GetHashCode will return consistent results for repeated values of a simple data type, for objects, it does not rely on the state of the member variables. Overriding GetHashCode by "xor"ing the hashcodes of the internal variables will return a consistent result.
Because hash codes can still collide, it is necessary to override the Equals method to ensure that the hashtable can correctly tell when a key is unique to the collection. What we want is value equality rather than instance equality which is the default for object types.
The documentation states also that if you override GetHashCode you must also override Equals for this reason. The documentation also explained that you could implement IComparable which would also work with a hashtable, although I never tried it.
Here is an example:
Public Class Key1
    Public X As String
    Public Y As Int32

    Public Sub New(ByVal s As String, ByVal i As Int32)
        X = s
        Y = i
    End Sub

    Public Overrides Function GetHashCode() As Integer
        'Xor has the advantage of not overflowing the integer.
        Return X.GetHashCode Xor Y.GetHashCode

    End Function
    Public Overloads Overrides Function Equals(ByVal Obj As Object) As Boolean
        Dim oKey As Key1 = CType(Obj, Key1)
        Return (oKey.X = Me.X And oKey.Y = Me.Y)
    End Function

End Class



الاثنين، 3 أكتوبر 2011

Multi-Sites Builder Pro

EgeCMS is the first Multi-Sites Builder, it can manage servial sites with different types. eg, News,Press Release,Software Download, Shareware Affiliate, Blog,Forum etc. Using the Form Maker Online tools, then edit diffrent pages' content online (What You See Is What You Get ) with different property, make it possible to build multi-sites on one server,and publish individual site which the Domain binded with other server to remote server automatically.



The web page path is neat and orderly , all Html pages published, with some tools of SEO, it's the best sites marketing system.


* Builder multi sites with one system..
* Form Maker online, makes you edit pages with different items.
* Pages Version Management, record the history of pages.
* All Html pages published, even Catalog,Tag,Searh,Rss pages.
* Authority of user group expand easily.
* Suck up the pad file data.
* Rss Creator and Sitemap Creator.
* The Greate Search function, and build more html pages with high keywords density
* Asp.net 2.0+MS SQL , supported on any server system environment.
EgeCMS Multi-Sites Builder Pro is the only one Multi sites manager, adapt to the highest Web Marketing technology, with the assistance of User Group management, EgeCMS meet the marketing management of big company's Web Marketing, and make it possible to build a Service System.
Using EgeCMS Multi-Sites Builder Pro:
* Friendly with Google and Yahoo.
* Any template support, and you can copy a sites with no miss.
* The management of editor,manager,admimistrator helps you manage your company.
* The authority management of Page Publish, and record the every edition of pages, helps you back up all datas and optimize easily.
* The public datas shared, it's a individual function , helps you manage important marketing datas.
* Automatically publish the individual sites, manage multi sites on different server.
* Free support and service.

Download now

Difference Between PHP programming and ASP Net Programming


Whenever there is a need for inter-linking hugely databases to generate database driven websites, web programmers or web developers unanimously agree on using PHP programming or ASP.Net programming. ASP ( Active-server-pages) and PHP ( Hyper text preprocessor) are considered as the two most popular and standard web programming languages because of their unique advantages over other web development languages.
Web Easy Professional 8.0Both ASP.Net and PHP are developed to provide support to dynamic database driven websites. ASP.Net works smoothly on Microsoft products and it can be used with only IIS (Internet Information Server); whereas PHP can be run on any kind of platform as well as it can be connected with different types of databases.

ASP.Net is comparatively new programming language which was launched in 2002 by Microsoft. This web development language is best for building web applications, web services and dynamic websites.
On the other hand PHP was launched in 1995 by Rasmus Lerdorf. It is an open source software and it can be downloaded for free under the PHP license. PHP and ASP.Net have some other differences too, which are elaborated below:


  • Database Compatibility

As PHP uses MySQL for the purpose of database connectivity, it is highly flexible in nature. Another important fact is that it will incur extra expenditure because MySQL can be accessed for free. Whereas, ASP.Net uses MS-SQL for connecting database but MS-SQL can not be availed free from Microsoft.


  • Cost

Linux can be used for running PHP programs and Linux is free operating system. Therefore, the cost of developing a website in PHP language is remarkably low. On the other hand, you need to install Internet Information Server (IIS)on a Windows server platform if you want to run ASP.Net program. As Windows server platform is not a free product, the cost of production is bounded to be increased.


  • General Run Time

It has been observed that ASP.Net code runs slower than PHP code. This is because ASP.Net utilizes server space while running whereas inbuilt memory space is used by PHP while running.


Sell online with Volusion

  • Coding Simplicity



ASP.Net codes are somewhat complicated and a web developer needs to work hard to get the hang of it. But PHP codes are very simple and a programmer does not have to make a diligent effort because it is comparatively easier than other types of programming languages.


  • Platform Connectivity Issue

ASP codes are usually run on Windows platforms but if you install ASP-Apache in the server than it can run on Linux platform as well. PHP has a unique advantage in this issue. Its codes can be linked with different types of platforms such as Windows, Linux and UNIX.


  • Cost of Tools

PHP codes are available for free in various forums and blogs as it is a open source software. Furthermore, some useful tools that can be used in PHP are also available for free. However, no such free tools are available for ASP.Net.


  • Background Language Support

The codes that are used in PHP are very much similar to that of C++ language and its syntax resembles the syntax used in C and C++. Therefore, if you have a fair knowledge in C++ or C, you will not face any difficulty while coding PHP language. However, the syntax of ASP is more or less similar to that of Visual basic syntax and this is all but simple.


  • Security

Though PHP can offer enough measures for ensuring data security, ASP. Net is reputed for creating sophisticated techniques to ensure the safety of confidential data. This is the reason why government organizations opt for ASP.Net.