Sunday, September 22, 2013

Post Data on asp.net Page using Javascript/Jquery


Method : Post

function AjaxCalltoPostData(datastring) {
    var xmlhttp;
    var responsestring;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                  responsestring = xmlhttp.responseText;
         }
    }
    var data = "content=" + datastring;
    xmlhttp.open("POST", "TempPage.aspx", true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(data);

}

On Page Load of TempPage.aspx Get Data using :
string content = Request["content"];
*******************************************************************************

Method : Get

 function AjaxCallUsingGetMethod() {
        var xmlhttp;
        var responsestring;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {         
                responsestring= xmlhttp.responseText;   
            }
        }
        xmlhttp.open("GET", "TempPage.aspx?func=getdata&source=" + $('#txtsource').val() + "&dest=" + $('#txtdestination').val() + "&fdate=" + $('#datetoday').val() + "", true);
        xmlhttp.send();

    }

On Page Load of TempPage.aspx Get Data using :

  string funname = Convert.ToString(Request.QueryString["func"]);
            if ((funname  + "").Trim().ToLower() == "getdata")
            {
                string src = Convert.ToString(Request.QueryString["source"]);
                string dest = Convert.ToString(Request.QueryString["dest"]);
                DateTime fdate = Convert.ToDateTime(Request.QueryString["fdate"]);
                string xmlres = GetDataFromASPFunc(src, dest, fdate);
                Response.Write(xmlres);
            }

Execute SQL File Using Command Prompt

Execute .sql file using command prompt

sqlcmd -S IPAddress/ServerName -d DatabaseName -i sqlfilepath -U username -P Password

Sample :

sqlcmd -S 127.0.0.1 -d MySampleDB -i C:\TSQL.sql -U mysqluserid -P mypassword


List of Arguments

Sqlcmd
  [-U login id]          [-P password]
  [-S server]            [-H hostname]          [-E trusted connection]
  [-d database name] [-l login timeout]     [-t query timeout]
  [-h headers]           [-s colseparator]      [-w screen width]
  [-a packetsize]        [-e echo input]        [-I Enable Quoted Identifiers]
  [-c cmdend]            [-L[c] list servers[clean output]]
  [-q "cmdline query"]   [-Q "cmdline query" and exit]
  [-m errorlevel]        [-V severitylevel]     [-W remove trailing spaces]
  [-u unicode output]    [-r[0|1] msgs to stderr]
  [-i inputfile]         [-o outputfile]        [-z new password]
  [-f  | i:[,o:]] [-Z new password and exit]
  [-k[1|2] remove[replace] control characters]
  [-y variable length type display width]
  [-Y fixed length type display width]
  [-p[1] print statistics[colon format]]
  [-R use client regional setting]
  [-b On error batch abort]
  [-v var = "value"...]  [-A dedicated admin connection]
  [-X[1] disable commands, startup script, environment variables [and exit]]
  [-x disable variable substitution]
  [-? show syntax summary]