Friday, May 3, 2013

Abstract Class


Abstract Class
Abstract class is a special kind of class that cannot be instantiated. It only allows other classes to inherit from it but cannot be instantiated. These are the important point which are related to the abstract class.
  1. abstract class may contain concrete methods.
  2. class may contain non-public members.
  3. abstract class can be used as a single inheritance.
  4. abstract class can be invoked if a main() exists.
why we need a abstract class that cannot be instantiated 
It only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In other word, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.
Creating a abstract class
we use MustInherit keyword to create abstract class. Abstract classes can also specify abstract members. Like abstract classes, abstract members also provide no details regarding their implementation. Only the member type, access level, required parameters and return type are specified.  and to declare the abstract member we use the MustOverride keyword.
For example
Imports System.Console
Imports System.Math
Module Module1
    Public MustInherit Class Abstractclass
        Public MustOverride Function square() As Integer
        Public MustOverride Function cube() As Integer
    End Class
    Public Class AbstractFirst
        Inherits AbstractClass
        Dim A As Integer = 4
        Dim B As Integer = 5
        Public Overrides Function square() As Integer
            Return A * A
        End Function
        Public Overrides Function cube() As Integer
            Return B * B * B
        End Function
    End Class
    Sub Main()
        Dim abs1 As New AbstractFirst()
        WriteLine("square of A is :" & " " & abs1.square())
        WriteLine("Cube of B is :" & " " & abs1.cube())
        Read()
    End Sub
End Module

Thursday, January 3, 2013

Use controls property by loop in panel


    Public Sub ClearPanel(ByVal objPanel As Panel)
        Dim cntrl As Control
        For Each cntrl In objPanel.Controls
            If TypeOf cntrl Is TextBox Then
                cntrl.Text = ""
            ElseIf TypeOf cntrl Is CheckBox Then
                DirectCast(cntrl, CheckBox).Checked = False
            End If
        Next
    End Sub

Friday, December 28, 2012

What is difference between unique key and primary key?


There is two difference between them.
1. The not null constraint is by default added to primary key, it means, primary key attribute cannot accept null values, whereas, the attribute declared as unique can accept null values. It is the major difference between the two.
2. Secondly, we can have only one primary key in a relation, whereas, multiple attributes can be declared unique at the same time.

Friday, December 7, 2012

Binding Checked List box control with data


        CheckedListAccount.DataSource = Dset.Tables(0) ' Dataset containing datatable

        CheckedListAccount.DisplayMember = "account_name" 'display field
        CheckedListAccount.ValueMember = "account_id"        'id filed

'to get selected items id from checked list box


        For Each checkeditem As DataRowView In CheckedListAccount.CheckedItems
            MsgBox(checkeditem.Item("account_id").ToString())
        Next


Thursday, October 4, 2012

In SQL, what are the differences between primary, foreign, and unique keys?

In SQL, what are the differences between primary, foreign, and unique keys?

 
Both primary and unique keys can span multiple columns within a table. Two differences exist:
1. A table may have more than one unique key. This depends on the design of the table. But, a table can have only one primary key.
2. The values in the unique key columns may or may not be NULL. The values in primary key columns, however, can not be NULL.
While unique and primary keys both enforce uniqueness on the columns of one table, foreign keys define a relationship between 2 tables. A foreign key identifies a column or group of columns in one (referencing) table that refers to a column or group of columns in another (referenced) table.
Both unique and primary keys can be referenced by foreign keys.

Wednesday, October 3, 2012

What is the difference between SMALLDATETIME and DATETIME?


"What's that", you ask? You never heard of this SmallDateTime data type?

That does not change the fact that it does indeed exist. And yes, even your SQL Server 2000 has it!

Here are the main differences you should know about these two datetime types:

1. Range of Dates

A DateTime can range from January 1, 1753 to December 31, 9999.
A SmallDateTime can range from January 1, 1900 to June 6, 2079.

2. Accuracy

DateTime is accurate to three-hundredths of a second.
SmallDateTime is accurate to one minute.

3. Size

DateTime takes up 8 bytes of storage space.
SmallDateTime takes up 4 bytes of storage space.


Armed with this knowledge, you may want to use SmallDateTime instead of DateTime if you only need to represent dates from January 1, 1900 to June 6, 2079 and you do not need accuracy below 1 minute. Why? Simple! Using SmallDateTime will reduce the amount of data your queries are pulling back. The size of each row will be a bit smaller.


That's it for now... be sure to check back soon for more information on using datetime in SQL Server.

Friday, July 13, 2012

Search column name in tables in SQL Database


select
sc.name as col_name,so.name as table_name from syscolumns sc inner join sysobjects so on so.id=sc.id where sc.name like 'column_name' and so.xtype='U'