Monday 28 November 2011

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


Syntax:-
Select * into <New Table> from <Database.Dbo.Table>

Example:-
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 Asp.net 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)
    {
   
  //debugger;
        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;
//                      return true;
                  }
                else
                  {    
                        args.IsValid = false;
                        return;
//                        return false;
                  }       
        }   

    }



Custom Validator control Validation:

<asp:CustomValidator id="CheckUpdate"
        runat="server"
        ControlToValidate="TxtHidden"
        ValidateEmptyText="true"
        ClientValidationFunction="ConfirmApproval"
        Display="None">custom validator</asp:CustomValidator><br />



2). File Upload control custom Validation


Java Script :

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

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

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

    }


Custom Validator control Validation:

<asp:CustomValidator ID="CustomValidator1"
        runat="server"
        ClientValidationFunction="ValidateUpl"
        ControlToValidate="UplFile"
        ErrorMessage="CustomValidator" Display ="None"
        ValidateEmptyText="True"></asp:CustomValidator

Friday 18 November 2011

How to set Short Cut key in Asp.net Application Using Java Script


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

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


}

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)))
        Else
            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)
        Else
            cmd.Parameters.AddWithValue("@Client_active", 0)
        End If

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

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()

        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*/
)
as
begin

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,
Marital_status)

values(@Client_id,@Client_name,@Login_id,@Client_id,@Client_mobile,@Client_mobile2,@Client_email,@Client_email2,
@Client_dob,@Client_gender,@Client_active,getdate(),@Client_mar_status)
end

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 Asp.net(Web 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

        Next

    End Sub


How to Call:

if Form Controls:

clearAlltextbox(Me.Form.Controls)

if Panel Conrtols:

clearAlltextbox(Me.Panel2.Controls)