Thursday, November 28, 2013

Validate TxtBox For Mobile Number

Private Sub TxtNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNo.KeyPress
        If Asc(e.KeyChar) <> 8 Then
            If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Or TxtNo.Text.Length > 9 Then
                e.Handled = True
            End If
        End If
    End Sub

Tuesday, November 26, 2013

Reset Identity Column Value to 1 in SQL Database


To reset identity column value and start value from “1” during insert new records we need to write query to reset identity column value. Check below Query


DBCC CHECKIDENT (Table_Name, RESEED, New_Reseed_Value)

Table_Name is name of your identity column table

RESEED specifies that the current identity value should be changed.

New_Reseed_Value is the new value to use as the current value of the identity column.   
  

EX: DBCC CHECKIDENT ('UserDetails', RESEED, 0)

Once we run the above query it will reset the identity column in UserDetails table and starts identity column value from “1”



Monday, November 25, 2013

Create Word File in vb.net

First Import NameSpace
******************************************
Imports Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop
*******************************************
Public Sub createlog()
        Dim comtype1 As String
        Dim wrd As Word.Application
        Dim Doc As Word.Document
        wrd = CreateObject("Word.Application") 'Create Object
        Doc = wrd.Documents.Add()
        comtype1 = "-----BASIC COMPLAINT DETAILS-----"
        Dim strconnection As String = ConfigurationManager.ConnectionStrings("MyDb").ConnectionString
        cn = New SqlConnection(strconnection)
        da = New SqlDataAdapter("select * from call_description order by s_id  desc", cn)
        ds = New DataSet
        da.Fill(ds)
        If ds.Tables(0).Rows.Count - 1 Then
            With Doc.Application
                .Selection.Font.Size = "10"
                .Selection.Font.Name = "Verdana"
                .Selection.Font.Color = &H4696F7  'Orange Color
                .Selection.Font.Bold = True
                .Selection.TypeText(Text:=comtype1 & vbCrLf)
                .Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify
                .Selection.Font.Bold = False
                .Selection.Font.Color = WdColor.wdColorBlack
                .Selection.TypeText(Text:="COMPLAINT REGISTERED THROUGH PHONE " & vbCrLf)
                .Selection.TypeText(Text:="SERIOUSNESS OF COMPLAINT: " & vbCrLf)
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("call_type") & vbCrLf)
                .Selection.TypeText(Text:="COMPLAINT DATE: ")
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("date_time") & vbCrLf)
                .Selection.TypeText(Text:="NAME OF VICTIM: ")
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("VICTIM_NAME") & vbCrLf)
                .Selection.TypeText(Text:="STATE: ")
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("State") & vbCrLf)
                .Selection.TypeText(Text:="COMPLAINT DETAILS: " & vbCrLf)
                .Selection.TypeText(Text:=Trim(removeextras(CStr(ds.Tables(0).Rows(0).Item("Call_descrip")), vbCrLf)))
            End With
            wrd.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyFormFields, , "admin")
            wrd.ActiveDocument.SaveAs("C:\Documents and Settings\CLIENT4\My Documents\word\Log.doc")
            wrd.ActiveDocument.Close()
            wrd.Quit()
            ' Doc = Nothing
            ' wrd = Nothing
        End If
    End Sub
**************************
 Function removeextras(ByVal sstring As String, ByVal delim As String) As String
        While (sstring Like "*" & delim & delim & "*")
            sstring = Replace(sstring, delim & delim, delim)
        End While
        removeextras = sstring
    End Function

Saturday, November 16, 2013

difference between primary key and unique key and foreign key and composite key in sql

  1. Super Key

    Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.Example : Primary key, Unique key, Alternate key are subset of Super Keys.
  2. Candidate Key

    A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.
    Example: In below diagram ID, RollNo and EnrollNo are Candidate Keys since all these three fields can be work as Primary Key.
  3. Primary Key

    Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.
  4. Alternate key

    A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.
    Example: In below diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.
  5. Composite/Compound Key

    Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.
  6. Unique Key

    Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article Difference between primary key and unique key.
    Foreign Key
  7. Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.
    Example : We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.
    Defined Keys 
    CREATE TABLE Department 
    (
DeptID int PRIMARY KEY,
Name varchar (50) NOT NULL,
Address varchar (200) NOT NULL, ) 
CREATE TABLE Student 
(
ID int PRIMARY KEY,
RollNo varchar(10) NOT NULL,
Name varchar(50) NOT NULL,
EnrollNo varchar(50) UNIQUE,
Address varchar(200) NOT NULL,
DeptID int FOREIGN KEY REFERENCES Department(DeptID)
)
Note
Practically in database, we have only three types of keys Primary Key, Unique Key and Foreign Key. Other types of keys are only concepts of RDBMS that we need to know.

Thursday, November 14, 2013

What is difference between dll and exe?

Exe
1.These are outbound file.
2.Only one exe file exists per application.
3. .Exe cannot be shared with other applications.

dll
1.These are inbund file .
2.Many dll files may exists in one application.
3.  dll can be shared with other applications.