Fast Export Excel with Database Records in .NET C# || Quick Export to Excel || Fast Export to Excel

Export Records in Excel Very Quickly.



Step 1: Add Package of EPPlus

https://www.nuget.org/packages/EPPlus/

dotnet add package EPPlus --version 6.1.3

==================================================================

Step 2: Implementation on .cs page.

using OfficeOpenXml;

namespace ExportExcel

{

private async void Export()

{

// Collect data from database and store in DataTable object 

System.Data.DataTable dt = await GetDataToExport(); 

using (var package = new ExcelPackage())

            {

                // Add a new worksheet to the package

                var worksheet = package.Workbook.Worksheets.Add("Sheet1");

                for (int i = 0; i < dt.Rows.Count; i++)

                {

                    await Task.Run(() =>

                    {

                        worksheet.Cells[i + 1, 1].Value = dt.Rows[i][0];

                        worksheet.Cells[i + 1, 2].Value = dt.Rows[i][1];

                        worksheet.Cells[i + 1, 3].Value = dt.Rows[i][2];

                        worksheet.Cells[i + 1, 4].Value = dt.Rows[i][3];

                    });

                }


                DependencyMethods methods = new DependencyMethods();

                // get file location using wpf tool

                methods.SaveAppSettings("TOOL_EXPORT_PATH", txtExportDirectoryPath.Text.Trim());

                string path = System.IO.Path.Combine(txtExportDirectoryPath.Text, txtFileName.Text);

                // Save the package to a file

                //package.SaveAs(new FileInfo("output.xlsx"));

                package.SaveAs(path);

            }

}

}

==================================================================


Step 3: Add Below line under appsettings tag into App.Config file.


<add key="EPPlus:ExcelPackage.LicenseContext" value="NonCommercial" />





Delete all log files from windows 7 using cmd


IN windows 7

-------------------------------------------------------

-------------------------------------------------------
1. open cmd
2. type: cd\
3. type: Del *.log /a /s /q /f

/a : singifies all.
/s : delete from all sub folders.
/q : bars from any prompts to ask for yes or no question.
/f : forcibly remove the files.
-------------------------------------------------------

-------------------------------------------------------

VISUAL STUDIO PRODUCT KEYS


Microsoft Visual Studio 2010 Ultimate Product Key
YCFHQ9DWCYDKV88T2TMHG7BHP

Visual Studio 2010 Professional
YCFHQ-9DWCY-DKV88-T2TMH-G7BHP OR YCFHQ 9DWCY DKV88 T2TMH G7BHP

Visual Studio 2012 Ultimate
RBCXF-CVBGR-382MK-DFHJ4-C69G8
Visual Studio 2012 professional
4D974-9QX42-9Y43G-YJ7JG-JDYBP
 RBCXF-CVBGR-382MK-DFHJ4-C69G8
YKCW6-BPFPF-BT8C9-7DCTH-QXGWC   

Visual Studio 2013 Ultimate
BWG7X-J98B3-W34RT-33B3R-JVYW9


=========================================

Visual Studio 2019 Enterprise
BF8Y8-GN2QH-T84XB-QVY3B-RC4DF
Visual Studio 2019 Professional
NYWVH-HT4XC-R2WYW-9Y3CM-X4V3Y

(Thanks: https://gist.github.com/ahtazaz/cec94a5cb97593ce49e5a3d613f90441)

=========================================


how to Replace null value with 0 Using C#

how to Replace null value with 0 Using C#



//here we suppose that objDataTable have data collection as table now access this //datatable object.

decimal j = 0;

 j = objDataTable.Rows[0]["Qty"] == DBNull.Value ? 0 : Convert.ToDecimal(objDataTable.Rows[0]["Qty"]);




NOTE :-
//if  DBNull.value is null then  "0 " else  "your code here") 
// ? = then
// : = else




Thank You
[Sumit Singh Shekhawat]

how to Replace null value with 0 in sql server 2008


Replace null value with 0 in sql server 2008


Summary : how to a null value convert into 0.


solution : ISNULL ( check_expression , replacement_value )

declare @a float;
set @a  = ISNULL((select SUM(CONVERT(FLOAT,quentity)) as qty  from Cutting 
                   WHERE jobno = '1' and contractorname = 'submit'),0)


-- here when quentity is null then it is return "0" else your calculate value;


Thank You

[Sumit Singh Shekhawat]

Add bak file in sql server 2008

step by step explain how to add bak file into your sql server 2008


1- Click Start, select All Programs, click Microsoft SQL Server 2008 and select SQL Server Management Studio. This will bring up the Connect to Server dialog box. Ensure that the Server name YourServerName and that Authentication is set to Windows Authentication. Click Connect.

2- On the right, right-click Databases and select Restore Database. This will bring up the Restore Database window.

3- On the Restore Database screen, select the From Device radio button and click the … box. This will bring up the Specify Backup screen.

4- On the Specify Backup screen, click Add. This will bring up the Locate Backup File.

5- Select the DBBackup folder and chose your BackUp File.

6- On the Restore Database screen, under Select the backup sets to restore: place a check in the Restore box, next to your data and in the drop-down next to To database: select DbName.

7- Ok your done.

Basic Delegates Example in ASP.NET

Delegates and Events

People often find it difficult to see the difference between events and delegates. C# doesn't help matters by allowing you to declare field-like eventswhich are automatically backed by a delegate variable of the same name. This article aims to clarify the matter for you. Another source of confusion is the overloading of the term "delegate". Sometimes it is used to mean a delegate type, and at other times it can be used to mean an instance of a delegate type. I'll use "delegate type" and "delegate instance" to distinguish between them, and "delegate" when talking about the whole topic in a general sense.

Delegate types

In some ways, you can think of a delegate type as being a bit like an interface with a single method. It specifies the signature of a method, and when you have a delegate instance, you can make a call to it as if it were a method with the same signature. Delegates provide other features, but the ability to make calls with a particular signature is the reason for the existence of the delegate concept. Delegates hold a reference to a method, and (for instance methods) a reference to the target object the method should be called on.
Delegates types are declared with the delegate keyword. They can appear either on their own or nested within a class, as shown below.
namespace DelegateArticle
{
    public delegate string FirstDelegate (int x);
  
    public class Sample
    {
        public delegate void SecondDelegate (char a, char b);
    }
}
This code declares two delegate types. The first is DelegateArticle.FirstDelegate which has a single parameter of type int and returns a string. The second is DelegateArticle.Sample.SecondDelegate which has two char parameters, and doesn't return anything (because the return type is specified as void).
Note that the delegate keyword doesn't always mean that a delegate type is being declared. The same keyword is used when creating instances of the delegate type using anonymous methods.
The types declared here derive from System.MulticastDelegate, which in turn derives from System.Delegate. In practice, you'll only see delegate types deriving from MulticastDelegate. The difference between Delegate and MulticastDelegate is largely historical; in betas of .NET 1.0 the difference was significant (and annoying) - Microsoft considered merging the two types together, but decided it was too late in the release cycle to make such a major change. You can pretty much pretend that they're only one type.
Any delegate type you create has the members inherited from its parent types, one constructor with parameters of object and IntPtr and three extra methods: InvokeBeginInvoke and EndInvoke. We'll come back to the constructor in a minute. The methods can't be inherited from anything, because the signatures vary according to the signature the delegate is declared with. Using the sample code above, the first delegate has the following methods:
public string Invoke (int x);
public System.IAsyncResult BeginInvoke(int x, System.AsyncCallback callback, object state);
public string EndInvoke(IAsyncResult result);
As you can see, the return type of Invoke and EndInvoke matches that of the declaration signature, as are the parameters of Invoke and the first parameters of BeginInvoke. We'll see the purpose of Invoke in the next section, and cover BeginInvoke and EndInvoke in the section on advanced usage. It's a bit premature to talk about calling methods when we don't know how to create an instance, however. We'll cover that (and more) in the next section.