Friday, April 17, 2015

sql Adding an identity to an existing column

You can't alter the existing columns for identity.
You have 2 options,
  1. Create a new table with identity & drop the existing table
  2. Create a new column with identity & drop the existing column
Approach 1. (New table) Here you can retain the existing data values on the newly created identity column.
CREATE TABLE dbo.Tmp_Names
    (
      Id int NOT NULL
             IDENTITY(1, 1),
      Name varchar(50) NULL
    )
ON  [PRIMARY]
go

SET IDENTITY_INSERT dbo.Tmp_Names ON
go

IF EXISTS ( SELECT  *
            FROM    dbo.Names ) 
    INSERT  INTO dbo.Tmp_Names ( Id, Name )
            SELECT  Id,
                    Name
            FROM    dbo.Names TABLOCKX
go

SET IDENTITY_INSERT dbo.Tmp_Names OFF
go

DROP TABLE dbo.Names
go

Exec sp_rename 'Tmp_Names', 'Names'
Approach 2 (New column) You can’t retain the existing data values on the newly created identity column, The identity column will hold the sequence of number.
Alter Table Names
Add Id_new Int Identity(1, 1)
Go

Alter Table Names Drop Column ID
Go

Exec sp_rename 'Names.Id_new', 'ID', 'Column'

asp.net dropdownlist set first value using jquery

$('#<%=ddl.ClientID%>').prop('selectedIndex', 0);

html tooltip hover

<input border='0' type='image' style='border-width:0px;' title='Edit' id='imgEditUser'>


---title='Edit'

Thursday, April 16, 2015

asp.net check valid emailid

  private static bool ValidateEmail(string email)
        {

            try
            {
                string TextToValidate = email;
                Regex expression = new Regex(@"\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}");

                // test email address with expression
                if (expression.IsMatch(TextToValidate))
                {
                    // is valid email address
                    return true;
                }
                else
                {
                    // is not valid email address
                    return false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

jquery check valid emailid

  if (!(txtEmail == "" || txtEmail == null || txtEmail == undefined)) {

                var email = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                if (!email.test(txtEmail)) {
                    $('#sp').text("Please enter valid email address.")
                    $('#sp').show();
                    validateFlag = false;
                }
                else {
                    $('#sp').hide();
                }

            }

jQuery/Javascript function to clear all the fields of a form [duplicate]

$('#myForm').trigger("reset");

javascript ajax parameters

1) async -

A Boolean value indicating whether the request should be handled asynchronous or not. Default is true

2) contentType - 

The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded"

3) data -

Specifies data to be sent to the server

4) error(xhr,status,error) -

A function to run if the request fails.

5) success(result,status,xhr

A function to be run when the request succeeds

6) type 

Specifies the type of request. (GET or POST)

7) url -

Specifies the URL to send the request to. Default is the current page

 var model = { Id: ID}
  $.ajax({
                url: baseUrl + '/Case/Get',
                type: 'POST',
                data: JSON.stringify(model),
                async: false,
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                                                                  
                    }

                },
                error: function (x, y, z) {
                    alert(x + '\n' + y + '\n' + z);
                }
            });