Thursday 11 October 2018

Date time Picker / Calendar in ASP.Net Visual Studio with Jquery with Sample Code

DateTime Picker / Calendar in ASP.Net Visual Studio with Jquery with Sample Code

Step 1Download Jquery utility used in this Sample Project
-----------------------------------------------------------------------------------------------
Step 2 - Extract the above Jquery.rar And Put it in your project folder
-----------------------------------------------------------------------------------------------
Step 3 - Create a class file JQueryUtils under Util namespace as follows 

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Util
{
    public class JQueryUtils
    {
        public static void RegisterTextBoxForDatePicker(Page page, params TextBox[] textBoxes)
        {
            RegisterTextBoxForDatePicker(page, "dd/mm/yy", textBoxes);
        }

        public static void RegisterTextBoxForDatePicker(Page page, string format, params TextBox[] textBoxes)
        {
            bool allTextBoxNull = true;
            foreach (TextBox textBox in textBoxes)
            {
                if (textBox != null) allTextBoxNull = false;
            }

            if (allTextBoxNull) return;

            page.ClientScript.RegisterClientScriptInclude(page.GetType(), "jquery", "JQuery/jquery.js");
            page.ClientScript.RegisterClientScriptInclude(page.GetType(), "jquery.ui.all", "JQuery/ui/jquery.ui.all.js");
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "datepickerCss", "<link  rel=\"stylesheet\" href=\"JQuery/themes/flora/flora.datepicker.css\" />");

            StringBuilder sb = new StringBuilder();
            sb.Append("$(document).ready(function() {");
            foreach (TextBox textBox in textBoxes)
            {
                if (textBox != null)
                {
                    sb.Append("$('#" + textBox.ClientID + "').datepicker({dateFormat: \"" + format + "\"});");
                }
            }
            sb.Append("});");
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "jQueryScript", sb.ToString(), true);
        }
    }
}
----------------------------------------------------------------------------------------
Step 4 - Now on your .aspx page let suppose it is Default.aspx,  add a text box control as follow -

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Date Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>
</body>

</html>
-------------------------------------------------------------------------------------------

Step 5 - Now in the code page of above .aspx page (step4) Default.aspx.cs add following line of code in page load event 

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Util.JQueryUtils.RegisterTextBoxForDatePicker(Page, TextBox1);  
    }
}

* Please note above underline control name is same as in .aspx page.
-------------------------------------------------------------------------------------------




Wednesday 3 October 2018

Execute SQL queries with a batch file or Command Line



Execute SQL queries with a batch file or Command Line

  • OSQL is a command line tool that allows you to issue commands to Microsoft SQL Server.
  • The OSQL allows you to enter Transact-SQL statements, system procedures, and script files.  This utility uses ODBC to communicate with the server.
  •  Once you have the OSQL command written, save the entire line into a file with a .bat extension.

Command Arguments:
-S (SQL Server\Instance name) Ex. -S nicsw5\SQL Express
-E (Uses a trusted connection instead of requesting a password)
-U (Login ID)
-P (Password)
-i (Input file) Ex. -i "c:\Folder\Script.sql"
-o (Output file) Ex. -o "c:\Folder\ScriptLog.txt"

Syntax :

  • Using Windows Authentication
osql -S nicsw5\SQL Express -E  -i "c:\Script_file.sql" -o "c:\Script_file_log.txt"

  •  Using SQL Authentication
osql -S nicsw5\SQL Express -U sql_user -P sql_password  -i "c:\Script_file.sql" -o "c:\Script_file_log.txt"


SQL Table : Change Row As Column and Group Them... ( Setting column values as column names in the SQL query result )

Setting column values as column names in the SQL query result Problem Statement : id col1 col2 1 Pending 30 1 Resolved 48 ...