Archive for August, 2008

Sql server date time functionality

August 20, 2008

Select * from users where convert(char,createddate,101)=’07/29/2008′

select cast(getdate() as char)

Resetting the table identity values

August 20, 2008

To reset the identity value in database table

 

Syntax: DBCC checkident (tablename, reseed, 0)

 

DBCC checkident can reseed the value of the table. For e.g.: our table has 25 records with 25 as last identity. If we want next record to have identity has 35 we need to run following T-SQL

 

DBCC checkidetnt (tablename, reseed, 34)

 

Disadvantage: It will violate the uniqueness.

Copying one table values into another table.

August 20, 2008

INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact
WHERE EmailPromotion = 2
–Verify that Data in TestTable
SELECT FirstName, LastName
FROM TestTable

IF it is in different database.
INSERT INTO SmithNephewStoreFront.dbo.category ( [Name],parentcategoryID)
SELECT  category,subcatid
FROM endo.dbo.category
WHERE catid = 2

resetting the identity column in the database table .

August 20, 2008

 

DBCC CHECKIDENT (category, RESEED, 0)

Assign a value to a textbox which is in password mode

August 20, 2008

Assign a value to a textbox which is in password mode
[ Assign password value to a text box]
 txtPassword.Attributes.Add(“value”, password);

Avoid duplicate insertion while page refresh

August 18, 2008

 

 Whenever you insert one record and after that if u click on refresh, again the same record insert once again. To avoid that we can use the following code in page load. And whereever u want simply u can use
if (!isrefresh){ }

 

 

 

 

if (Session["postid"] != null && ViewState["postid"] != null)

{

if (ViewState["postid"].ToString() != Session["postid"

].ToString()) 
 

 

 

IsPageRefresh =
 

 

true;
}
Session["postid"] = System.Guid.NewGuid().ToString();
ViewState["postid"] = Session["postid"];

select dropdown list value using javascript

August 15, 2008

                  var i;
                   var colorValue;
                  var color control
                  
                   colorControl = document.getElementById(“drp”) ;
                 
                for(i=colorControl.options.length-1;i>=0;i–)
                {
                if(colorControl.options[i].selected)
                 {
                  colorValue = colorControl.options[i].value;
                 
                  }
                }