Total Pageviews

Tuesday, July 20, 2010

Concatanating SQL table column

Table as follows

JSKID Tickets
8765 Bobcat
1001 Bobcat
1001 Confined Spaces
1001 Road

Turn this table to following

JSKID Tickets
1001 Bobcat,Confined Spaces,Road
8765 Bobcat

Select tk1.[JSKID], stuff((SELECT ',' + [Tickets] FROM [tblTickets] tk where tk.[JSKID]= tk1.[JSKID] FOR XML PATH('')),1,2,'' ) AS Tickets from [tblTickets] tk1 group by tk1.[JSKID]

Saturday, July 10, 2010

Read All appsetting on web.config

This will read all appsetting collection on web.config or app.config

NameValueCollection mySettings = System.Configuration.ConfigurationSettings.AppSettings;
string connStr = mySettings["connectionString"];

Thursday, July 1, 2010

SQL Server- Script to rebuild all tables' indexes

USE DatabaseName --Enter the name of the database you want to reindex

DECLARE @TableName varchar(255)

DECLARE TableCursor CURSOR FOR

SELECT table_name

FROM information_schema.tables

WHERE table_type = 'base table'

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName

WHILE @@FETCH_STATUS = 0

BEGIN

DBCC DBREINDEX(@TableName,' ',90)

FETCH NEXT FROM TableCursor INTO @TableName
END

CLOSE TableCursor

DEALLOCATE TableCursor

Printing a Div in JAVAScript - Extended Version

This works in IE and Firefox, Mutiple Divs can be printed.

function PrintAllDivs(printDiv) {
if (typeof HTMLElement != "undefined" && !
HTMLElement.prototype.insertAdjacentElement) {
HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) {
switch (where) {
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode, this)
break;
case 'afterBegin':
this.insertBefore(parsedNode, this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling)
this.parentNode.insertBefore(parsedNode, this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}
}

HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr) {
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where, parsedHTML)
}


HTMLElement.prototype.insertAdjacentText = function(where, txtStr) {
var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where, parsedText)
}
}

var doc;
var contentDiv;
var content;

if (document.getElementById('printHiddenFrame') == null) {
document.body.insertAdjacentHTML("beforeEnd", "");
}
doc = printHiddenFrame.document;
doc.open();
doc.write("");
doc.write("");
doc.write("");
contentDiv = document.getElementById(printDiv);
if (contentDiv != null) {
doc.write(contentDiv.innerHTML);
}
ConvertToText(doc);
doc.write("");
setTimeout('document.getElementById(\'abc\')', 0);
doc.close();
return false;

}

function printHiddenPage() {

window.document.printHiddenFrame.focus();
window.document.printHiddenFrame.print();
}

function ConvertToText(doc) {
var f = doc.getElementsByTagName('textarea');

for (var i = 0; i < f.length; i++) {
var txt = doc.getElementById(f[i].id + 'Print');

f[i].style.display = 'none';
f[i].style.visibility = 'hidden';

if (txt != null) {
f[i].value == "" ? txt.innerHTML = " " : txt.innerHTML = f[i].value.replace(/\n\r/g, "

");
}
}
}