Sunday, September 13, 2009

RENAME COLUMN/ ADD COLUMN

IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DOCUMENT' AND COLUMN_NAME = 'DOCUMENTDUEDATE')
BEGIN
ALTER TABLE DOCUMENT ADD DOCUMENTDUEDATE DATETIME
END

--To rename an existing column
--EXEC sp_rename 'DOCUMENT.DUEDATE','DOCUMENTDUEDATE','COLUMN'

Tuesday, August 25, 2009

Anonymous Methods

Anonymous methods were introduced in C# 2.0 +. These are alternative for named methods. In simple terms these are "Inline Methods".

Monday, August 24, 2009

Create XML Document

< ?xml version="1.0" encoding="utf-8"? > < >XML< /MainCategory > < >This is a list my XML articles.< /Description> < >true< /Active> < /Category >< /CategoryList >Here's the code:
< %@ Import Namespace="System.Data" % >
< %@ Import Namespace="System.Xml" % >
< %@ Page Language="C#" Debug="true" % >
< runat="server">
void Page_Load(object sender, System.EventArgs e){
if(!Page.IsPostBack){
XmlDocument xmlDoc = new XmlDocument();
// Write down the XML declaration
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);
// Create the root element
XmlElement rootNode = xmlDoc.CreateElement("CategoryList");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);
// Create a new element and add it to the root node
XmlElement parentNode = xmlDoc.CreateElement("Category");
// Set attribute name and value!
parentNode.SetAttribute("ID", "01");
xmlDoc.DocumentElement.PrependChild(parentNode);
// Create the required nodes
XmlElement mainNode = xmlDoc.CreateElement("MainCategory");
XmlElement descNode = xmlDoc.CreateElement("Description");
XmlElement activeNode = xmlDoc.CreateElement("Active");
// retrieve the text
XmlText categoryText= xmlDoc.CreateTextNode("XML");
XmlText descText = xmlDoc.CreateTextNode("This is a list my XML articles.");
XmlText activeText = xmlDoc.CreateTextNode("true");
// append the nodes to the parentNode without the value
parentNode.AppendChild(mainNode);
parentNode.AppendChild(descNode);
parentNode.AppendChild(activeNode);
// save the value of the fields into the nodes
mainNode.AppendChild(categoryText);
descNode.AppendChild(descText);
activeNode.AppendChild(activeText);
// Save to the XML file
xmlDoc.Save( Server.MapPath("categories.xml"));
Response.Write("XML file created");
}
}
< /script>


< script runat="server" >
void Page_Load(object sender, System.EventArgs e){
if(!Page.IsPostBack){
XmlDocument xmlDoc = new XmlDocument();
// Write down the XML declaration
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);
// Create the root element
XmlElement rootNode = xmlDoc.CreateElement("CategoryList");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);
// Create a new element and add it to the root node
XmlElement parentNode = xmlDoc.CreateElement("Category");
// Set attribute name and value!
parentNode.SetAttribute("ID", "01");
xmlDoc.DocumentElement.PrependChild(parentNode);
// Create the required nodes
XmlElement mainNode = xmlDoc.CreateElement("MainCategory");
XmlElement descNode = xmlDoc.CreateElement("Description");
XmlElement activeNode = xmlDoc.CreateElement("Active");
// retrieve the text
XmlText categoryText= xmlDoc.CreateTextNode("XML");
XmlText descText = xmlDoc.CreateTextNode("This is a list my XML articles.");
XmlText activeText = xmlDoc.CreateTextNode("true");
// append the nodes to the parentNode without the value
parentNode.AppendChild(mainNode);
parentNode.AppendChild(descNode);
parentNode.AppendChild(activeNode);
// save the value of the fields into the nodes
mainNode.AppendChild(categoryText);
descNode.AppendChild(descText);
activeNode.AppendChild(activeText);
// Save to the XML file
xmlDoc.Save( Server.MapPath("categories.xml"));
Response.Write("XML file created");
}
}
< /script >

Wednesday, August 19, 2009

Difference between "ref" and "out"

Both are used when sending arguments by reference instead of values. Both should be explicitly written in the calling function and called function. The main difference is that in "ref" the function expects that the reference sent is already initiated. Where as "out" does not expect it to be initiated or it ignores the initiation of the type.
I will be spending more time on this later...

Monday, August 17, 2009

PAGE METHOD

function GetdueDateFromSever() {
var state = document.getElementById("ctl00_cplHolderDefault_ddlIssueState").options[document.getElementById("ctl00_cplHolderDefault_ddlIssueState").selectedIndex].value;
var receivedDate = document.getElementById("ctl00_cplHolderDefault_wdcInqReceivedDate_input").value;
var dateOfLetter = document.getElementById("ctl00_cplHolderDefault_wdcDateOfLetter_input").value;
var inquiryType = document.getElementById("ctl00_cplHolderDefault_ddlInquiryType").options[document.getElementById("ctl00_cplHolderDefault_ddlInquiryType").selectedIndex].value;
var responsibleFunction = document.getElementById("ctl00_cplHolderDefault_lstResponsibleFunction");
var responsiblefunction1 = '';
for (var i = 0; i < responsibleFunction.options.length; ++i) {
if (responsibleFunction.options[i].selected == true) {
responsiblefunction1 = responsiblefunction1.concat(responsibleFunction.options[i].value + ',')
}
}

//
var varResult;
if (state != -1 && receivedDate != "") {
var varWebRequest = new Sys.Net.WebRequest();
varWebRequest.set_httpVerb('POST');
varWebRequest.get_headers()['Content-Type'] = 'application/json; charset=utf-8';
//
//, subEntityName: subEntityName
var varUrlParams = { receivedDate: receivedDate, state: state, inquiryType: inquiryType, responsiblefunction1: responsiblefunction1, dateOfLetter: dateOfLetter };
varWebRequest.set_url(Sys.Net.WebRequest._createUrl(PageMethods.get_path() + "/getDueDateFromServer", varUrlParams));
var varBody = null;
varBody = Sys.Serialization.JavaScriptSerializer.serialize(varUrlParams);
if (varBody === "{}") varBody = "";
varWebRequest.set_body(varBody);
//
var varExecutor = new Sys.Net.XMLHttpSyncExecutor();
varWebRequest.set_executor(varExecutor);
varWebRequest.invoke();
//
if (varExecutor.get_responseAvailable())
varResult = varExecutor.get_object();

document.getElementById("ctl00_cplHolderDefault_wdcDueDate_input").value = varResult;
document.getElementById("ctl00_cplHolderDefault_hdnDueDate").value = varResult;
}
}











[WebMethod()]
[ScriptMethod()]
public static string getDueDateFromServer(string receivedDate, string state, string inquiryType, string responsiblefunction1, string dateOfLetter)
{
CSSI.VUE.CS.Web.Service.Inquiry.SchemaHeader sh = WebHelper.GetServiceSoapHeader("INQUIRY", "INQUIRYRESEARCHREP1DATASCHEMA") as CSSI.VUE.CS.Web.Service.Inquiry.SchemaHeader;
InquiryService inquiryService = WebHelper.GetInquiryService();
inquiryService.SchemaHeaderValue = sh;
XmlDocument xdDueDateList = new XmlDocument();
xdDueDateList.LoadXml(@"" + state + "" + receivedDate + "" + dateOfLetter + "" + inquiryType + "" + responsiblefunction1 + "");
////
XmlNode xnUserList = inquiryService.GetDueDateByState(xdDueDateList);

string dueDate = xnUserList.SelectSingleNode("//DUEDATE").InnerText;
if (dueDate == "01/01/1900")
{
dueDate = "";
}
return dueDate;
}

Sunday, August 16, 2009

RAISE ERROR

RAISERROR ('User does not have privileges to perform this action.' -- Message text.
,11 -- Severity
,1 -- State
,N'number' -- First argument.
,5);
RETURN

Saturday, August 15, 2009

ALTER TABLE ADD NEW COLUMN

ALTER TABLE table_name ADD column_name datatype
ALTER TABLE table_name DROP COLUMN column_name

ALTER TABLE table_name ALTER COLUMN column_name datatype