Tuesday, October 31, 2023

Logical SQL query processing order of query clauses



1 FROM (Joins if available)
2 WHERE 
3 GROUP BY 
4 HAVING 
5 SELECT
    5.1 SELECT list
    5.2 DISTINCT
6 ORDER BY  

7 TOP / OFFSET-FETCH 

Thursday, March 16, 2023

Sample Code for Get appSetting config value in .Net Core application

 I have created Sample class to the Key Values from application (appSettings.json). for that i have initialise the Configuration instance at Constructor level. Later on consumed same instance to get the Key Value.

Sample Code is Below

Calling from application

string Conn = ConfigurationExtension.GetConfigKeyValue("ConnectionStrings:DBConnection").ToString();

Base Code 

    public class ConfigurationExtension

    {

        IConfiguration configuration;

        public ConfigurationExtension()

        {

            var builder = new ConfigurationBuilder()

                .AddJsonFile("appSettings.json");

            configuration = builder.Build();

        }


        /// <summary>

        /// Get appSettings json key value ex Key: "ConnectionStrings:DBConnection"

        /// </summary>

        /// <param name="Key"></param>

        /// <returns></returns>

        public static string GetConfigKeyValue(string Key) {

            ConfigurationExtension obj = new ConfigurationExtension();            

            string con = obj.configuration[Key].ToString();

            return con;

        }

    }


Friday, January 27, 2023

Sample

using Syncfusion.XlsIO;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;


using Syncfusion.DocIO;

using Syncfusion.DocIO.DLS;


private void SyncFileDocDemo() 

        {

            //Creates an empty Word document instance

            WordDocument document = new WordDocument();

            //Loads or opens an existing word document through Open method of WordDocument class

            document.Open(Server.MapPath(@"SpreadSheet.docx"));


            document.Save(Server.MapPath("Result\\SpreadSheet.odt"), FormatType.Odt);

        }


        private void SyncFuExcelData() 

        {

            //Step 1 : Instantiate the spreadsheet creation engine.

            ExcelEngine excelEngine = new ExcelEngine();

            //Step 2 : Instantiate the excel application object.

            IApplication application = excelEngine.Excel;


            //A new workbook is created.[Equivalent to creating a new workbook in Microsoft Excel]

            //The new workbook will have 12 worksheets

            IWorkbook workbook = application.Workbooks.Open(Server.MapPath(@"SpreadSheet.xls"));


            string SaveOption = "Xls";

            try

            {

                //Saving the workbook to disk.

                if (SaveOption == "Xls")

                {

                    //Save as .xls format

                    workbook.SaveAs(Server.MapPath("Result\\SpreadSheet.ods"), HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97);

                }

                //Save as .xlsx format

                else

                {

                    workbook.Version = ExcelVersion.Excel2016;

                    workbook.SaveAs("SpreadSheet.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016);

                }

            }

            catch (Exception)

            {

            }

        }

Monday, January 16, 2023

Generate Excel Bulk Report in Asp.Net With Extension method

To Generate the faster report for bulk data i used following code base for the download the data. Sample Code is :-

Supporting DLL is Click here (ClosedXML.dll)

 if (dtBase != null && dtBase.Rows.Count > 0)
        {
            if (dtBase.Rows.Count > 0)
            {
                dtBase.ExportExcel("VKYC_Report", "VKYC_Report");
            }
            else
            {
                lblError.Text = "Records not found.";
            }
        }
        else
        {
            lblError.Text = "Records not found.";
        }
-------------------------

public static class Extension
{
    public static void ExportExcel(this DataTable dt, string WorksheetName = "Report", string FileName = "Report")
    {
        try
        {
            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt, WorksheetName);
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Buffer = true;
                    HttpContext.Current.Response.Charset = "";
                    HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + FileName + ".xlsx");
                    using (MemoryStream MyMemoryStream = new MemoryStream())
                    {
                        wb.SaveAs(MyMemoryStream);
                        MyMemoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
                        HttpContext.Current.Response.Flush();
                        HttpContext.Current.Response.End();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            // throw;
        }
    }
}