ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

SQL Server : Export data to excel using export data wizard


In this article I am going to explain how to export data to excel file using SQL Server export data wizard.


There are many ways to export data to excel from SQL server. Here I am going to explain how you can export the data to excel file using export data wizard. This feature is available in SSMS (SQL Server management Studio).


Open SQL Server management Studio and connect to server. Right on database from which you want to export the data. Here I have select Northwind database. Right click on it, go to Task and select Export data.
SQL Server : Drop or delete all tables from database

SQL Server : Drop or delete all tables from database


In this article I am going to explain how to drop or delete all tables from SQL Server database.

In SQL Server, there is hidden store to delete all tables. Once you connect to SQL and execute this store procedure, it’s executed for each table.

EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"

If tables are referenced by foreign key constraints, in that case you have run this again and again to till all foreign key constraints delete.

Download Microsoft Northwind, AdventureWorks and Pubs sample database for SQL Server


In this article I am going to how to download Microsoft Northwind, AdventureWorks and Pubs sample database for SQL Server.

Download Microsoft Northwind, AdventureWorks and Pubs sample database for SQL Server


Northwind, AdventureWorks and Pubs databases are available free by Microsoft and can download script and back up of these databases. For Northwind and Pubs database script file is available and for AdventureWorks both script and Backup are available.

Go to this link and you will saw the link to download the script and Backup.

Download SQL Server 2017


In this article I am going to explain how to download Sql Server 2017.

We have 3 options to download the Sql server:

    1.     Sql server on premises
If  you are planning to buy the license then you can download this version, otherwise you have 180 days trial. This version have all features.

    2.    Sql server developer edition
This version of sql server is free and also includes all features. But you can’t use this version in production. Personally I want to recommend this version for development and training purposes.

    3.     Sql server Express
This version is also free and can be used in production. But the disadvantages is, it doesn’t include all features and limitation in data storage. It can store data upto 10 GB.

Sql Server: how to change the state of database


In this article I am going to explain how to change the state (Read only to Read Write and vice versa) of Sql server database.

Description:
While working on window form application, I have face the issue of read only database on data insert.

Solution:
To resolve this issue we have 2 ways. One using Sql server management studio and 2nd one using Sql query.

Asp.net MVC : Implement infinite scroll using Jquery

Here in this article I am going to explain how to implement infinite scroll using Jquery in asp.net MVC application.

Description:
I am showing list of country in application. Instead of pagination want to show all records on scroll. To fulfill this requirement I am using Jquery.

Implementation:

Model class:
   public partial class CountryMaster
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string CountryCode { get; set; }
    }

Add Controller
Add an empty controller to project.

Complete source code of Controller:

MVC : Cascading DropdownList

Introduction: In this article today I am going to explain how we can Populate Cascading Dropdown List in Asp.net MVC4 using Json and Jquery
Populate Cascading Dropdown
(Click to Enlarge)
Description:

I want to populate State dropdown on Country selection and on State Dropdown Selection populate City dropdown. I have three classes in model CountryState and City.
Country:
using System.ComponentModel.DataAnnotations;

public class Country
    {
        [Key]
        public int CountryId { getset; }
        public string CountryName { getset; }

        public virtual ICollection<State> States { getset; }
    }

State:

Hello world application with Angular 6


Here in this tutorial I am going to explain how to create hello world application with Angular 6.

Prerequisite 

a.  Visual studio code
b.  Node.js

You can download the latest version of Visual studio code from here and Node.js from here.
Node.js installation will also install the npm. After installation start the visual studio code. If you see the message of Git is missing then you have to install the git to your system. You can download latest version here or in visual studio code  there is link in message to download git, when you click on the link it will redirect you to download link.

How to change password in MVC application


In this article I am going to explain how to change password in MVC application. 

Description:
I want to add change password functionality for logged in users. To change password users have to enter current password, after that new password and confirm the new password.
  

Implementations:
Please check the previous post Create login form and maintain authenticated user’s detail in MVC application.

Model

How to generate numeric and alphanumeric OTP (one time password) in MVC application


Here in this article I am going to explain how to generate numeric and alphanumeric OTP (one time password) in MVC application.

Description:
I want to generate OTP. OTP can be numeric or alphanumeric and it is used widely to validate the user’s information such as mobile number, in banks for transaction etc.

Implementation:

Add controller
Add an empty controller to project. Create 3 action to generate OTP, one to generate numeric and 2nd one alphanumeric.
Generate random password in MVC application

Generate random password in MVC application


In this article I am going to explain how to generate random password in MVC application.


Description:
I want to generate strong random password for users when they registers to website. Here in this article I am going to generate password using 2 ways.


Implementation:
Add an empty controller to project. I have create action Generatepassword.

  public ActionResult Generatepassword()
        {
            return View();
        }

Using Membership Generate method
ASP.NET MVC : Display data in 2 or more columns

ASP.NET MVC : Display data in 2 or more columns


In this article I am going to explain how to display data in 2 or more columns in MVC application.

Description:
I want to display data in 3 columns. To display data 2 or more columns we have 2 approaches. One use the Bootstarp, if use the bootstrap it adjust itself. 2nd one using the loop, run the loop and differentiate them like odd and even. For 2nd one check this article.

Implementation:
Model

MVC : Generate random OTP (one time password)


In this article I am going to explain how to generate random OTP (one time password) in asp.net MVC application.

Description:
I want to generate OTP. OTP can be numeric or alphanumeric and it is used widely to validate the user’s information such as mobile number, in banks for transaction etc.

Implementation:

Add controller
Add an empty controller to project. Create 3 action to generate OTP, one to generate numeric and 2nd one alphanumeric.

Complete code of controller:

How to show data in 2 columns in MVC application


In this article I am going to explain how to show data in 2 columns in MVC application.

Description:
I am displaying list of all countries in MVC application one record per row but I want to display data in 2 columns. 2 records pre row.

Implementations:

Model

How to crop image using Iedit Jquery in MVC application

In this article I am going to explain how to crop image using Iedit Jquery and save to folder in MVC application.

Description:
In MVC application, want to add functionality to crop the image. When user’s uploading profile image, they can crop the uploaded image and it will be save to image folder. I am using IEdit Jquery plugin to crop the profile image. You can download the IEdit Jquery from here.

Implementation:
Add Controller:
Add an empty controller to project. Create action to upload profile pic.

Convert Image to Base64 string and Base64 string to Image in asp.net MVC application

In this article I am going to explain how to convert Image to Base64 string and Base64 string to Image in asp.net MVC application.

Description:
In MVC application want to convert Image to Base64 and Base64 encoded string to Image.

Implementation:
Add empty controller to project. Create method to convert Image and Base64 encoded string.

Complete code to Controller :

ASP.NET MVC : Crop image and save cropped image to folder

In this article I am going to explain how to crop image and save cropped image to folder in MVC using Jquery.

Description:
In MVC application, want to add functionality to crop the image. When user’s uploading profile image, they can crop the uploaded image and it will be save to image folder. I am using IEdit Jquery plugin to crop the profile image. You can download the IEdit Jquery from here.

Implementation:

Add Controller:

SQL SERVER : Create database from .MDF & .LDF file

In this article I am going to explain how to create database from .MDF & .LDF file in Sql server.

Description & Implementation:
I have .MDF and .LDF file of database. I want to restore or create database from these files. We have 2 ways to create database from .MDF and .LDF file.

Method 1: Using  T-Sql
Run the below given query :

How to display username of logged in users in MVC application

In this artic article I am going to explain how to display username of logged in users in MVC application.

Description:
In MVC project I have created login form. After successfully logged in, want to show users name on top right hand side. I am using Tempdata to maintain the user’s detail.

Implementation:

ASP.NET : Get Month name, number, year and number of days from given date

In this article I am going to explain how to get Month name, number, year and number of days from selected date in asp.net.


Description:
I want to get the month name, number, year and number of days in selected month.

Implementation:

HTML markup of webform:

Create login form and maintain authenticated user’s detail in MVC application

In this artic article I am going to explain how to create login form and maintain authenticated user’s detail in MVC application.

Description:
I want to create login form and maintain the authenticated user’s detail in application. I am using Tempdata to maintain the user’s detail.

Implementation:

Model: