Monday, 28 November 2011

How to Create table as Same as another Database table using query

Select * into <New Table> from <Database.Dbo.Table>

select * into Menu_master from accord.dbo.Menu_master

Q. What is the Difference between Delete and Truncate Command

Q. What is the Difference between Delete and Truncate Command

   Delete                                Truncate

1) Delete Record do not              1) The record will       save until they                        be remove permanently
are committed and they                 by the truncate command
can be Roll backed.        
2) Delete Command effects in          2) Truncate command do
   Triggers.                             not effect Triggers

3) It Process is slow                 3) Process fast as 
                                         compare to Delete

Saturday, 26 November 2011

How to Validate server side controls in using Custom Validator

Some times we require that the page should not be submitted when server side control is being used.

We have two kinds of server side control validation as given below:
1). TextBox Custom Validation
2). File Upload control custom Validation

1). TextBox Custom Validation

Java Script :

function ConfirmApproval(source, args)
        var t1 = document.getElementById("TxtCurrDate").value;
        var t2 = args.Value//document.getElementById("TxtHidden").value;
        if(args.Value == t1)
//            alert('hello');
//            }
                var r=confirm("The Price on this Date are already in Database, Do Your Really wants to Update !");
                if (r==true)
                        args.IsValid = true;
//                      return true;
                        args.IsValid = false;
//                        return false;


Custom Validator control Validation:

<asp:CustomValidator id="CheckUpdate"
        Display="None">custom validator</asp:CustomValidator><br />

2). File Upload control custom Validation

Java Script :

function ValidateUpl(source, args)
        var fuData = document.getElementById('<%= UplFile.ClientID %>');
        var FileUploadPath = fuData.value;

            if(FileUploadPath =='')
                 alert('Please choose Excel file for update Rate list.');
                 args.IsValid = false;
                 var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();

                if (Extension == "xls")
                args.IsValid = true; // Valid file type
                alert('Please choose Excel file for Update Rate list.');
                args.IsValid = false; // Not valid file type


Custom Validator control Validation:

<asp:CustomValidator ID="CustomValidator1"
        ErrorMessage="CustomValidator" Display ="None"

Friday, 18 November 2011

How to set Short Cut key in Application Using Java Script

//This line is very Importance
document.onkeydown = checkKeycode

function checkKeycode(e)
var keycode;
if (window.event)
keycode = window.event.keyCode;
    if (e.which == 113) // for F2 Key of Key board
    //keycode = e.which;
    //alert("keycode: " + keycode);


Thursday, 10 November 2011

How to access Output parameter value of Stored Procedure in ASP.NET (Look on Carefully Colored Area)

Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click

'Define a sql parameter for SP Output Argument

        Dim MaxClientId As New SqlParameter("@MaxClientId", SqlDbType.Int)
        MaxClientId.Direction = ParameterDirection.Output

        Dim cmd As SqlCommand = New SqlCommand("SpClientMaster", conn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@Client_id", Val(TxtClientId.Text))
        cmd.Parameters.AddWithValue("@Client_name", TxtName.Text)

        If TxtDob.Text.Length > 0 Then
            cmd.Parameters.AddWithValue("@Client_dob", (mf.mdyDate(TxtDob.Text)))
            cmd.Parameters.AddWithValue("@Client_dob", DBNull.Value)
        End If
        cmd.Parameters.AddWithValue("@Client_gender", DdlGender.SelectedValue)
        cmd.Parameters.AddWithValue("@Client_mar_status", DdlMaritalStatus.SelectedValue)
        cmd.Parameters.AddWithValue("@Client_mobile", TxtMobile1.Text)
        cmd.Parameters.AddWithValue("@Client_mobile2", TxtMobile2.Text)

        cmd.Parameters.AddWithValue("@Client_email", TxtEmail1.Text)
        cmd.Parameters.AddWithValue("@Client_email2", TxtEmail2.Text)

        cmd.Parameters.AddWithValue("@Login_id", Val(Session("Login_id")))

        If (ChkActive.Checked = True) Then
            cmd.Parameters.AddWithValue("@Client_active", 1)
            cmd.Parameters.AddWithValue("@Client_active", 0)
        End If

        cmd.Parameters.Add(MaxClientId) 'Value parameter 'being passed to sqlcommand object


        If Val(TxtClientId.Text) = 0 Then
            TxtClientId.Text = MaxClientId.Value.ToString()
        End If
    End Sub

Stored Procedure:

Alter Proc SpClientMaster
@Client_id int,
@Client_name varchar(50),
@Login_id int,
@Client_gender char(1),
@Client_dob datetime,
@Client_mar_status char(1),
@Client_mobile varchar(12),
@Client_mobile2 varchar(12),
@Client_email varchar(50),
@Client_email2 varchar(50),
@Client_active bit,

@MaxClientId int output  /* define a Output parameter valiable*/

set @Client_id = (select isnull(max(Client_id),0) + 1 from Client_master)
set @MaxClientId = @Client_id  /* setting Output parameter value */
insert Client_master(Client_id,Name,Login_id,Password,Mobile,Mobile2,Email,Email2,Dob,Gender,Active,Create_dt,


Sunday, 6 November 2011

How to Close a Panel without effecting to the validation of form

Some times a user wants to Close a panel then it effects to Validation and it do not becomes close. just because any button becomes run on server and effect to submition of the form.

For that Purus a user should set the property of a button given below:

CausesValidation : False

Thursday, 3 November 2011

How to Clear All text Boxes and DropDownList in Applications)

Public Sub clearAlltextbox(ByVal fr As ControlCollection)
        For Each c As Control In fr
           If c.ToString.Equals("System.Web.UI.WebControls.TextBox"Then
                CType(c, TextBox).Text = ""
            End If

            If c.ToString.Equals("System.Web.UI.WebControls.DropDownList") Then
                CType(c, DropDownList).ClearSelection()
            End If


    End Sub

How to Call:

if Form Controls:


if Panel Conrtols: