Showing posts with label joins. Show all posts
Showing posts with label joins. Show all posts

Friday, September 25, 2015


Word reader dll


Add a reference to the dll "word_reader.dll", and also add a using Statement as "using word_reader;" To extract text, use: TextExtractor extractor = new TextExtractor(PathToWordDocument); string text = extractor.ExtractText(); //The string 'text' is now loaded with the text from the Word Document

Reset Identity Column in SqlServer

Using Truncate Method.
 Using DBCC (database consistency checker)
--- TRUNCATE TABLE cannot be used when a foreign key references the table to be truncated where as DBCC can.

here is the Query using DBCC


DBCC CHECKIDENT('Table Name', RESEED, 0)
In Above query '0' is the reset idetity seed number,you can give any number whatever you want like 100,200 etc.
---Here is the Query Using Truncate 
truncate table TableName


Joins Linq query

Inner Join
var empDetails = from emp in objEmp.Employees
                         join dept in objEmp.Depts on emp.Deptid equalsdept.DeptId
                         select new
                         {
                             emp.EmpName,
                             emp.Designation,
                             emp.Location,
                             dept.DeptName
                         };

Left Join
var empDetails = from emp in objEmp.Employees
                join dept in objEmp.Depts on emp.Deptid equals dept.DeptIdinto empdet
                         from de in empdet.DefaultIfEmpty()
                         select new
                         {
                             emp.EmpName,
                             emp.Designation,
                             emp.Location,
                             de.DeptName
                         };


Thursday, September 24, 2015

SQL Server Joins With Examples

Types of Joins
  1. Inner Join
  2. Outer Join
    • Left outer Join
    • Right outer Join
    • Full outer Join
  3. Cross Join
  4. Equi Join
  5. Self Join

CREATE TABLE EmployeeDetails (
  EmpId int PRIMARY KEY,
  EmpFirstName varchar(50),
  EmpLastName varchar(50),
  Department varchar(50),
  DepartID int
)

CREATE TABLE EmpSalary (
  EmpID int,
  EmpFullName varchar(80),
  EmpSalary int,
  EmpWorkingYears int
)

SELECT
  *
FROM EmpSalary

INSERT INTO EmpSalary (EmpId, EmpFullName)
  VALUES (1007, 'Naresh Choulla')

INSERT INTO EmpSalary (EmpId, EmpFullName)
  VALUES (1008, 'Choulla Naresh')


INSERT INTO EmployeeDetails
  VALUES (1001, 'Naresh', 'Choulla', 'IT', 2)
INSERT INTO EmployeeDetails
  VALUES (1002, 'Sachin', 'Tendulkar ', 'IT', 2)
INSERT INTO EmployeeDetails
  VALUES (1003, 'Prince', 'Mahesh', 'Accounts', 3)
INSERT INTO EmployeeDetails
  VALUES (1004, 'Shruti', 'hassan', 'HR', 1)
INSERT INTO EmployeeDetails
  VALUES (1005, 'anushka', 'sharma', 'IT', 2)
INSERT INTO EmployeeDetails
  VALUES (1006, 'Hyd', 'Hitech', 'Accounts', 3)
-----------------------------------
SELECT
  *
FROM EmpSalary

INSERT INTO EmpSalary
  VALUES (1001, 'naresh choulla', 35000, 3)
INSERT INTO EmpSalary
  VALUES (1002, 'Varun Sharma', 25000, 2)
INSERT INTO EmpSalary
  VALUES (1003, 'Jaspreet Sharma', 20000, 2)
INSERT INTO EmpSalary
  VALUES (1004, 'Shruti Sharma', 18000, 1)
INSERT INTO EmpSalary
  VALUES (1005, 'Shaili Sharma', 25000, 2)
INSERT INTO EmpSalary (EmpFullName, EmpSalary, EmpWorkingYears)
  VALUES ('Shaili Sharma', 6000, 1)


SELECT
  *
FROM EmpSalary
SELECT  * FROM EmployeeDetails
-- \inner join
SELECT
  EmployeeDetails.EmpId,
  EmployeeDetails.EmpFirstName,
  EmpSalary.EmpSalary
FROM EmployeeDetails
JOIN EmpSalary
  ON EmployeeDetails.EmpId = EmpSalary.EmpID

--  Left outer join

SELECT
  e.EmpId,
  e.EmpFirstName,
  e.DepartID,
  s.EmpSalary
FROM EmployeeDetails e
LEFT OUTER JOIN EmpSalary s
  ON e.EmpId = s.EmpID

SELECT
  e.EmpId,
  e.EmpFirstName,
  e.DepartID,
  s.EmpSalary
FROM EmployeeDetails e
RIGHT OUTER JOIN EmpSalary s
  ON e.EmpId = s.EmpID

SELECT
  e.EmpId,
  e.EmpFirstName,
  e.DepartID,
  s.EmpSalary
FROM EmployeeDetails e
FULL OUTER JOIN EmpSalary s
  ON e.EmpId = s.EmpID

-- Cross join
SELECT
  EmployeeDetails.EmpId,
  EmployeeDetails.EmpFirstName,
  EmpSalary.EmpSalary
FROM EmployeeDetails
CROSS JOIN EmpSalary
--on EmployeeDetails.EmpId = EmpSalary.EmpID

-- Equi Join

SELECT
  *
FROM EmployeeDetails
JOIN EmpSalary
  ON EmployeeDetails.EmpId = EmpSalary.EmpID

-- Self Join
SELECT
  *
FROM EmployeeDetails
ALTER TABLE EmployeeDetails
ADD ManagerID int

UPDATE EmployeeDetails
SET ManagerID = 1002
WHERE empid = 1001
UPDATE EmployeeDetails
SET ManagerID = 1002
WHERE empid = 1005
UPDATE EmployeeDetails
SET ManagerID = 1006
WHERE empid = 1003
UPDATE EmployeeDetails
SET ManagerID = 1004
WHERE empid = 1007
UPDATE EmployeeDetails
SET ManagerID = 1004
WHERE empid = 1008

SELECT
  *
FROM EmployeeDetails

SELECT
  a.EmpId,
  a.EmpFirstName AS ManagerName,
  b.EmpId AS ManagerID,
  b.EmpFirstName AS EmployeeName
FROM EmployeeDetails a,
     EmployeeDetails b
WHERE a.EmpId = b.ManagerID

CREATE TABLE computer (
  CompID int,
  computerDes varchar(100),
  Price int
)

DELETE FROM computer
WHERE CompID = 2
INSERT INTO computer
  VALUES (1, 'Pentium 4,1GB RAM', 25000)
INSERT INTO computer
  VALUES (2, 'Dual Core,2GB RAM', 35000)
CREATE TABLE Addon (
  id int,
  description varchar(100),
  price int
)
INSERT INTO Addon
  VALUES (1, 'Speakers', 5000)
INSERT INTO Addon
  VALUES (2, 'printer', 15000)

SELECT
  *
FROM computer
SELECT
  *
FROM Addon


SELECT
  computer.computerDes,
  Addon.description,
  computer.Price + Addon.price AS totalprice
FROM computer
CROSS JOIN Addon
--on EmployeeDetails.EmpId = EmpSalary.EmpID

Saturday, September 12, 2015

Join Query using Entity FrameWork

var customUser = (from u in context.Users
            join pr in context.PasswordRecoveries on u.Id equals pr.userId
            where pr.url == token && pr.requestDateTime.AddHours(12) <DateTime.Now
            select u).FirstOrDefault();


Wednesday, September 9, 2015

Incorrect UserName And Password

@using (Html.BeginForm("Login", "Account", new { id = "signin-form", ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post))
    {
        @Html.AntiForgeryToken()
        if (!ViewData.ModelState.IsValid)
        {
            <div class="alert alert-danger alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <strong>Error!</strong> Incorrect email or password
            </div>
        }


    }

Monday, September 7, 2015

How to Install or Uninstall C# .NET Windows Service || Windows service installation path || installutil.exe

C:\Windows\Microsoft.NET\Framework\v4.0.30319 

Introduction

how to install or uninstall a .NET Windows Service using C#. This article starts with an introduction of installing and uninstalling a .NET Windows Service using C#.


To install or uninstall Windows Service (that was created using the .NET Framework) use the utility InstallUtil.exe. This tool can be found in the following path.

Step 1

Open a Command Prompt window.

Open InstallUtil.exe in the directory for Framework 2.0; the path is “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\”.



Figure 1

Step 2

Then .NET service runs as a command similar to this (specify the full path to your service):

“InstallUtil.exe C:\DemoService\DemoWindowsService.exe”

Figure 2
Step 3

And if you want to uninstall a Windows Service then you just add ‘/u’ between installutil.exe and the path as in the following:

“InstallUtil.exe /u C:\DemoService\DemoWindowsService.exe”




Figure 3

Final Step

For doing a service check after installing you just open to the local services and find your service as in the following:



Figure 4