DECLARE @stSqlString NVARCHAR(MAX) = ''
DECLARE @stStrXml XML
SET @stSqlString = 'set @stStrXml=(select * from TableName FOR XML AUTO, elements)'
EXEC sp_executesql @stSqlString, N'@stStrXml XML OUTPUT',@stStrXml OUTPUT
SELECT @stStrXml
Tuesday, February 13, 2018
How to get list of all Folder in network sharing path using SQL Server
IF OBJECT_ID('tempdb..#TempTableName') IS NOT NULL
DROP TABLE #TempTableName ;
CREATE TABLE #TempTableName
(
id INT IDENTITY(1, 1) ,
subdirectory NVARCHAR(512) ,
depth INT
) ;
INSERT #TempTableName
( subdirectory
)
EXEC MASTER.dbo.xp_cmdshell 'dir DriveName:\ /b /o:n /ad'
IF NOT EXISTS ( SELECT 1
FROM #TempTableName )
BEGIN
EXEC XP_CMDSHELL 'net use DriveName: \\ServerName\DriveName /user:domain\USERNAME PASSWORD'---code for Mapping drive in local Pc
END
Create Window Service Setup Using .bat file
-----------------------------For Install-------------------------------------------------
@ECHO OFF
echo Installing WindowsService...
echo ---------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil /i C:\RapnetService\Debug\ImportRapnetData.exe
echo ---------------------------------------------------
echo Service Install Done Successfully.
pause
---------------------------------For Uninstall---------------------------------------------
@ECHO OFF
echo Installing WindowsService...
echo ---------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil /u C:\RapnetService\Debug\ImportRapnetData.exe
echo ---------------------------------------------------
echo Service UnInstall Done Successfully.
pause
Monday, February 12, 2018
Query For Calculate CPU Usage in SQL Server
SELECT TOP 10
ObjectName = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid)
,TextData = qt.text
,DiskReads = qs.total_physical_reads -- The worst reads, disk reads
,MemoryReads = qs.total_logical_reads --Logical Reads are memory reads
,Executions = qs.execution_count
,TotalCPUTime = qs.total_worker_time
,AverageCPUTime = qs.total_worker_time/qs.execution_count
,DiskWaitAndCPUTime = qs.total_elapsed_time
,MemoryWrites = qs.max_logical_writes
,DateCached = qs.creation_time
,DatabaseName = DB_Name(qt.dbid)
,LastExecutionTime = qs.last_execution_time
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
ORDER BY qs.total_worker_time DESC
-- Find queries that have the highest average CPU usage
SELECT TOP 10
ObjectName = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid)
,TextData = qt.text
,DiskReads = qs.total_physical_reads -- The worst reads, disk reads
,MemoryReads = qs.total_logical_reads --Logical Reads are memory reads
,Executions = qs.execution_count
,TotalCPUTime = qs.total_worker_time
,AverageCPUTime = qs.total_worker_time/qs.execution_count
,DiskWaitAndCPUTime = qs.total_elapsed_time
,MemoryWrites = qs.max_logical_writes
,DateCached = qs.creation_time
,DatabaseName = DB_Name(qt.dbid)
,LastExecutionTime = qs.last_execution_time
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
ORDER BY qs.total_worker_time/qs.execution_count DESC
Angular Project Demo
1) create Two Folder :- Controllers and Factory (WebApplication2 is project name)
-----------------------------------------MytestConroller.js---------------------------------------------------------
angular.module('WebApplication2.Controllers').controller('MytestController', MytestController);
MytestController.$inject = ['$scope', 'MyButtonClickEvent', '$http'];
function MytestController($scope, MyButtonClickEvent, $http) {
var vm = this;
$scope.username = 'World';
$scope.sayHello = function () {
//First Code
//$scope.greeting = MyButtonClickEvent.BtnClick($scope.username);
//MyButtonClickEvent.GetData($scope.username).then(function (result) {
// $scope.greeting = result.data.aaData;
//})
///Second Code
var item = { 'msgName': $scope.username }
MyButtonClickEvent.GetDataClass(item).then(function (result) {
debugger
$scope.greeting = result.data.aaData.msgName;
})
// third code
//var item = [];
//item.push({ msgName: $scope.username });
//MyButtonClickEvent.GetDataList(item).then(function (result) {
// $scope.greeting = result.data.aaData[0].msgName;
//})
};
}
-----------------------------------------MytestFactory.js---------------------------------------------------------
angular.module('WebApplication2.Services').service('MyButtonClickEvent', MyButtonClickEvent);
MyButtonClickEvent.$inject = ['$http'];
function MyButtonClickEvent($http) {
var list = {};
list.BtnClick = function (data) {
return 'Hello ' + data;
}
list.GetData = function (data) {
return $http({
url: '/Mytest/GetMsg',
method: "GET",
params: { MyData: data },
});
};
list.GetDataClass = function (data) {
return $http({
url: '/Mytest/GetMsgClass',
method: "GET",
params: data
});
};
list.GetDataList = function (myObject) {
return $http({
url: '/Mytest/GetMsgList',
method: "post",
data: myObject
});
};
return list;
}
-----------------------------------App.js--------------------------------------------------------------------
angular.module('WebApplication2', ['WebApplication2.Controllers', 'WebApplication2.Services']);
angular.module('WebApplication2.Controllers', []);
angular.module('WebApplication2.Services', []);
-----------------------------------Index.cshtml----------------------------------------------------------
MyData)
{
var JsonResult = Json(new { aaData = MyData }, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = Int32.MaxValue;
return JsonResult;
}
}
}
public class myList
{
public string msgName { get; set; }
}
----------------------------------Layout.cshtml-------------------------
Your name:
{{greeting}}
-------------------------------------Controller.cs--------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication2.Controllers
{
public class MytestController : Controller
{
// GET: Mytest
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetMsg(string MyData)
{
var JsonResult = Json(new { aaData = MyData }, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = Int32.MaxValue;
return JsonResult;
}
[HttpGet]
public JsonResult GetMsgClass(myList MyData)
{
var JsonResult = Json(new { aaData = MyData }, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = Int32.MaxValue;
return JsonResult;
}
[HttpPost]
public JsonResult GetMsgList(List{{greeting}}
File Upload in Angular 2
****************Change Event *************
onChange(event: EventTarget) {
let formData = new FormData();
let eventObj: MSInputMethodContext = event;
let target: HTMLInputElement = eventObj.target;
let files: FileList = target.files;
this.file = files[0];
let formData = new FormData();
formData.append('FileDocument', this.file);
return this.http.post(`UrlPath`, formData)
.map((res: Response) => {
});
}
******************WEB API******************
[HttpPost]
public void GetImage()
{
var ImageData= System.Web.HttpContext.Current.Request.Files["FileDocument"];
ImageData.SaveAs(Path);
}
Input Only Number in Iput Type in Angular 2
Input Only Number in Input Type in Angular 2
-- Html Code here
First Create Directive.ts File and Put Code Inside
*************************onlynumber.directive.ts***************************
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
selector: '[OnlyNumber]'
})
export class OnlyNumber {
constructor(private el: ElementRef) { }
@Input() OnlyNumber: boolean;
@HostListener('keydown', ['$event']) onKeyDown(event) {
let e = event;
if (e.which == 13) {
e.preventDefault();
var $next = $('[tabIndex=' + (+ parseInt(e.target['tabIndex']) + 1) + ']');
if (!$next.length) {
$next = $('[tabIndex=1]');
}
$next.focus();
}
else if (this.OnlyNumber) {
if ([46, 8, 9, 27, 13, 190].indexOf(e.keyCode) !== -1 ||
(e.keyCode == 65 && e.ctrlKey === true) ||
(e.keyCode == 67 && e.ctrlKey === true) ||
(e.keyCode == 88 && e.ctrlKey === true) ||
(e.keyCode >= 35 && e.keyCode <= 39)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
}
}
}
Passing Data To Component in Agular2 With Using Service
-------------Create First Service---------------
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class ProgressSpinner {
public _subject = new Subject();
public event = this._subject.asObservable();
public SpinnerLoader(data: any) {
this._subject.next(data);
}
}
------------Create Object in AppComponent--------------
import { Component } from '@angular/core';
import { alertservice, ProgressSpinner } from './shared'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
loading: boolean = false;
constructor(public _ProgressSpinner: ProgressSpinner) {
_ProgressSpinner.event.subscribe((data) => { this.loading = data });
}
}
***************Second Component***************
import { Component, OnInit, ViewEncapsulation, ElementRef } from '@angular/core'
import { MenuItem, Message, Shape_Master, Shape_Col } from '../../shared'
import { DepartmentGroupervice, GenericClass, Pagination, ProgressSpinner } from '../../shared'
import { ConfirmationService, GrowlModule } from 'primeng/primeng';
@Component({
selector: 'app-shape',
templateUrl: './shape.component.html',
styleUrls: ['./shape.component.css']
})
export class ShapeComponent implements OnInit {
constructor( private _ProgressSpinner: ProgressSpinner) {
this._ProgressSpinner.SpinnerLoader(false);
}
}
Sunday, January 21, 2018
Not Empty Table List In Sql Server
(
SELECT
SUM(row_count) AS [row_count],
OBJECT_NAME(OBJECT_ID) AS TableName
FROM
sys.dm_db_partition_stats
WHERE
index_id = 0 OR index_id = 1
GROUP BY
OBJECT_ID
)
SELECT *
FROM TableName
WHERE [row_count] > 0
Wednesday, January 10, 2018
Get Hour And minute, Second From Second in Sql Server
DECLARE @Second1 BIGINT=5401
SET @Second1=ABS(@Second1)
DECLARE @ETIME AS VARCHAR(20)
SELECT @ETIME = RIGHT(CAST(@Second1 / 3600 AS VARCHAR(10)),7) + '.' +
RIGHT('0' + CAST((@Second1 / 60) % 60 AS VARCHAR(10)),2) + ':' + RIGHT('0' + CAST(@Second1 % 60 AS VARCHAR(2)),2)
SELECT @ETIME
SET @Second1=ABS(@Second1)
DECLARE @ETIME AS VARCHAR(20)
SELECT @ETIME = RIGHT(CAST(@Second1 / 3600 AS VARCHAR(10)),7) + '.' +
RIGHT('0' + CAST((@Second1 / 60) % 60 AS VARCHAR(10)),2) + ':' + RIGHT('0' + CAST(@Second1 % 60 AS VARCHAR(2)),2)
SELECT @ETIME
Location:
United States
Convert Minute To Hour in SQL Server function
CREATE FUNCTION [dbo].[MinToHour]
(
@Second1 BIGINT=0
)
RETURNS TIME
AS
BEGIN
DECLARE @Res TIME =NULL
SET @Second1=ABS(@Second1)
DECLARE @ETIME AS VARCHAR(20)
SELECT @ETIME = RIGHT(CAST(@Second1 / 60 AS VARCHAR(10)),7) + '.' + RIGHT('0' + CAST((@Second1) % 60 AS VARCHAR(10)),2)
SELECT @RES= CAST(REPLACE(@ETIME,'.',':') AS TIME)
RETURN @RES
END
(
@Second1 BIGINT=0
)
RETURNS TIME
AS
BEGIN
DECLARE @Res TIME =NULL
SET @Second1=ABS(@Second1)
DECLARE @ETIME AS VARCHAR(20)
SELECT @ETIME = RIGHT(CAST(@Second1 / 60 AS VARCHAR(10)),7) + '.' + RIGHT('0' + CAST((@Second1) % 60 AS VARCHAR(10)),2)
SELECT @RES= CAST(REPLACE(@ETIME,'.',':') AS TIME)
RETURN @RES
END
Convert Second to Hour in Sql Server function
CREATE FUNCTION [dbo].[SecTOHour]
(
@Second1 BIGINT=0
)
RETURNS TIME
AS
BEGIN
DECLARE @Res TIME =NULL
SET @Second1=ABS(@Second1)
DECLARE @ETIME AS VARCHAR(20)
SELECT @ETIME = RIGHT(CAST(@Second1 / 3600 AS VARCHAR(10)),7) + '.' +
RIGHT('0' + CAST((@Second1 / 60) % 60 AS VARCHAR(10)),2) + ':' + RIGHT('0' + CAST(@Second1 % 60 AS VARCHAR(2)),2)
SELECT @RES= CAST(REPLACE(@ETIME,'.',':') AS TIME)
RETURN @RES
END
(
@Second1 BIGINT=0
)
RETURNS TIME
AS
BEGIN
DECLARE @Res TIME =NULL
SET @Second1=ABS(@Second1)
DECLARE @ETIME AS VARCHAR(20)
SELECT @ETIME = RIGHT(CAST(@Second1 / 3600 AS VARCHAR(10)),7) + '.' +
RIGHT('0' + CAST((@Second1 / 60) % 60 AS VARCHAR(10)),2) + ':' + RIGHT('0' + CAST(@Second1 % 60 AS VARCHAR(2)),2)
SELECT @RES= CAST(REPLACE(@ETIME,'.',':') AS TIME)
RETURN @RES
END
Tuesday, January 9, 2018
Rotate image in asp.net
public void FlipImage(string Filename, string FileNameNew)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath("/images/") + Filename);
//Rotate the image in memory
img.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
System.IO.File.Delete(System.Web.Hosting.HostingEnvironment.MapPath("/images/" + FileNameNew));
//save the image out to the file
img.Save(System.Web.Hosting.HostingEnvironment.MapPath("/images/" + FileNameNew));
//release image file
img.Dispose();
}
{
System.Drawing.Image img = System.Drawing.Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath("/images/") + Filename);
//Rotate the image in memory
img.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
System.IO.File.Delete(System.Web.Hosting.HostingEnvironment.MapPath("/images/" + FileNameNew));
//save the image out to the file
img.Save(System.Web.Hosting.HostingEnvironment.MapPath("/images/" + FileNameNew));
//release image file
img.Dispose();
}
Saturday, September 9, 2017
Split value using Charindex in SQL Server
Convert (varchar,Substring('11/12',0,charindex('/','11/12')))
OutPut => 11
OutPut => 11
Friday, June 23, 2017
Turning a Comma Separated string into individual rows in Sql Server
select t.ID,x.Code
from Emp t
cross apply (select Code from dbo.Split(t.Data,',') ) x
from Emp t
cross apply (select Code from dbo.Split(t.Data,',') ) x
Wednesday, May 24, 2017
Solve - How to show a string in indian rupees format in C#.net?
double dblAmt=134600.00;
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN");
string StrAmt = dblAmt.ToString("N2", info);
txtAmt.Text = StrAmt;
Output := 1,34,600.00
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN");
string StrAmt = dblAmt.ToString("N2", info);
txtAmt.Text = StrAmt;
Output := 1,34,600.00
Thursday, May 4, 2017
Find Tables With Foreign Key Constraint in SQL Server
SELECT f.name AS ForeignKey,
SCHEMA_NAME(f.SCHEMA_ID) SchemaName,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id
SCHEMA_NAME(f.SCHEMA_ID) SchemaName,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id
Monday, September 26, 2016
INI File Read and Write in C#.Net
- text file Read and Write in C#.Net
public class
File
{
private
string
filePath;
[DllImport(
"kernel32"
)]
private
static
extern
long
WritePrivateProfileString(
string
section,
string
key,
string
val,
string
filePath);
[DllImport(
"kernel32"
)]
private
static
extern
int
GetPrivateProfileString(
string
section,
string
key,
string
def,
StringBuilder retVal,
int
size,
string
filePath);
public
File(
string
filePath)
{
this
.filePath = filePath;
}
public
void
Write(
string
section,
string
key,
string
value)
{
WritePrivateProfileString(section, key, value.ToLower(),
this
.filePath);
}
public
string
Read(
string
section,
string
key)
{
StringBuilder SB =
new
StringBuilder(255);
int
i = GetPrivateProfileString(section, key,
""
, SB, 255,
this
.filePath);
return
SB.ToString();
}
public
string
FilePath
{
get
{
return
this
.filePath; }
set
{
this
.filePath = value; }
}
}
Subscribe to:
Posts (Atom)