Nov 24, 2015

Ternary Operator in ASP.Net Gridview and JavaScript

Ternary Operator is used to test a condition.

Advantage of using this Ternary Operator we can skip multiple lines of code that used for IF..ELSE / SWITCH Statements at Some specific situations where there is no need to return values.

Syntax :
int i = 5.ToString() == "5" ? "Yes It's Five" : "No It's not Five";

Here 
// We are using ternary operator ?
// if the condition is true then its return "Yes It's Five"
// if the condition is false then its return "No It's not Five"

here output is "Yes It's Five".

recently i faced one situation in ASP.Net Gridview along with JavaScript Using in my project.

In Gridview i'm displaying Client Details along with EMail Ids and their passwords with ***** Symbols for passwords, but some of my clients Email Ids were too long with their names then gridview alignment problems came into picture and i need to show an alert when user clicks on password column in gridview.

Let's See ASP.Net Source Code







In JavaScript :




I hope you will enjoy this code.

Thanks & Regards
       RAJ








Oct 19, 2015

SET ANSI_NULLS ON/OFF & SET QUOTED_IDENTIFIER ON/OFF in SQL Server ?

Hi,

SET ANSI_NULLS ON / OFF
GO

SET QUOTED_IDENTIFIER ON / OFF
GO

These we can notify at creating new Stored Procedure in Sql Server.

ANSI Stands for American National Standards Institute .

When to use ON / OFF.

For Example i had a table named "Person.Address"

My Table data looks like when i used a simple select query.

Query 1: 

SELECT     AddressID, AddressLine1, AddressLine2, City
FROM   Person.Address

Result :


Now i am using SET ANSI_NULLS ON :

Query 2:

SET ANSI_NULLS ON
SELECT  AddressID, AddressLine1, AddressLine2, City
FROM   Person.Address
WHERE AddressLine2 < > NULL
AND AddressLine2 = NULL

Result :


Note :
When  SET ANSI_NULLS ON, Equals (=), not equals (< >) comparison against a null value in WHERE condition in SELECT Statement it returns zero rows even if the column contains NULL values or any data. 
Because it will not follow the SQL-92 standard.


Now i am using SET ANSI_NULLS OFF :

Query 3:

SET ANSI_NULLS OFF
SELECT AddressID, AddressLine1, AddressLine2, City
FROM  Person.Address
WHERE AddressLine2 < > NULL

Result :

Query 4:

SET ANSI_NULLS OFF
SELECT AddressID, AddressLine1, AddressLine2, City
FROM  Person.Address
WHERE AddressLine2 = NULL

Result :

Note :
When  SET ANSI_NULLS OFF, Equals (=), not equals (< >) comparison against a null value in WHERE condition in SELECT Statement it returns if the column contains any null values when (=), and it returns if the column contains any data when (< >).
Because it follows the SQL-92 standard.

Same way we can use these ANSI_NULLS {ON/OFF} in creating Stored Procedures.

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


SET QUOTED_IDENTIFIER ON / OFF


In SET QUOTED_IDENTIFIER ON / OFF

When it is ON, Any character set in double quotes (" ") treated as T-SQL Identifier like (SP Name, Table Name and Column Name etc .....). Here i am giving column name in double quotes.

For Example : Same Table

Query 5:

SET QUOTED_IDENTIFIER ON

SELECT AddressID, AddressLine1, "AddressLine2", City
FROM  Person.Address
WHERE AddressLine2 < > NULL

Result :



When it is OFF, it will be treated as string, and it gives that string value in quotes as a result with no column name, but in case if table it will throw the error like Incorrect syntax near Table Name.

Query 6: For Column Name in double quotes

SET QUOTED_IDENTIFIER OFF

SELECT AddressID, AddressLine1, "AddressLine2", City
FROM  Person.Address
WHERE AddressLine2 < > NULL

Result :




Query 7 : For Table Name in double quotes

SET QUOTED_IDENTIFIER OFF

SELECT AddressID, AddressLine1, AddressLine2, City
FROM  "Person.Address"
WHERE AddressLine2 < > NULL

Result :


I hope you will enjoy this information

Thanks & Regards 
RAJ













Oct 9, 2015

Special permissions on drive for copy and paste options

Hi,

Today i came across one query like this 

In my PC D-Drive, access permissions sharing like copy and paste 

Users in the same network, can copy files from my D-Drive, folders / subfolders,
but they can't paste in my D-Drive directly.

But they can paste files in selected folders / subfolders in my D-Drive.

Simply,

1. Copy : Full permissions from D-Drive, folders and subfolders too.
2. Paste : Limited permissions users can paste files in selected folders and subfolders only not in the D-Drive directly.

So please follow these steps :

1. Go to your D-Drive, right click ==> properties
2. Go to security tab, select Users, click on Edit, please check only these 
  a. Read & Execute
  b. List Folder Contents
  c. Read
3. Click on Apply and ok.

Images :

Fig 1

Fig 2

Fig 3


This will given you only copy / read permission to everyone in the network.

Now we have to give paste / write permission for all or selected folders in D-Drive.

4. Open your D-Drive
5. Select your Folder, right click on folder, go to properties
6. Go to Sharing tab, and click on share
7. One pop-up will come with the name File Sharing, Click on the dropdown select Everyone and add it
8. Change permission Level Read to Read/Write, Click on Share
9. This may take few minutes for processing
10. Now you can paste / write files in this selected folder in D-Drive.

Images :

Fig 4

Fig 5

Fig 6

Fig 7


Like this you can follow the same steps for giving the write / paste permissions to all folders.

Thanks & Regards
RAJKUMAR






Sep 23, 2015

Some Tricky SQL Queries

Hi,

select count(*) -- // 1 

select 15 -- // 15

select $   -- // 0.00 

select count('7') -- // 1 

select 'RAJ'+1 -- // Conversion Problem Error

select 'RAJ'+'1' -- // RAJ1

select (select 'RAJ') -- // RAJ

select select 'RAJ' -- // Error

select * from 'RAJ' -- // Error

select * from AccountDetials,ACTSBankDetails -- // o/p will be cross join of both tables

select count(*) + count(*) -- // 2

select 'Rajkumar Palnati HDFC' from AccountDetials -- // 'Rajkumar Palnati HDFC'

select sum(1+2*3) --// 7

select max(1+2*3) -- // 7

select max(1,2,3) -- //  Error, The max function requires 1 argument(s)

select max('RAJ') -- // RAJ

select count(select Client from AccountDetials) -- // Error syntax 


Thanks & Regards
Rajkumar Palnati

Sep 12, 2015

Dynamic Query in Stored Procedure with parameter as a single field

Hi,

In Sql Server Stored Procedure we can create dynamic queries with single or multiple parameters

Here i am passing i/p parameter as table for dynamic query

Example :

CREATE procedure sp_RetrieveBasedOnField
@TableName varchar(50) -- i/p 
as
begin
declare @Query as nvarchar(255)
set @Query=N'select * from '+ @TableName +N''
exec sp_ExecuteSQL @Query
end


This is simple as we can pass our table name and executes dynamic query.

Thank you


Differences between Functions and Stored Procedures in Sql Server

Hi,


1) Procedure can return zero or n values whereas function can return one value which is mandatory

2) Procedures can have input, output parameters for it whereas functions can have only input parameters

3) Procedure allows select as well as DML(
INSERT/UPDATE/DELETE) statements in it whereas function allows only select statement in it

4) Functions can be called from procedure whereas procedures cannot be called from function

5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function

6) We can go for transaction management in procedure whereas we can't go in function

7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.

Thanks & Regards
RAJ

ADO.NET Object Model

Hi,

ADO.NET is designed to help developers work efficiently with multi tier databases, across intranet or Internet scenarios.

The ADO.NET object model consists of two key components as follows:


1. Connected model 2. Disconnected model



  • Connected model (.NET Data Provider - a set of components including the Connection, Command, DataReader, and DataAdapter objects)
  • Disconnected model (DataSet).

For better please go through these links about ADO.Net objects.





What is ASP.NET Application file or What is the use of Global.asax file events in asp.net ?

Hi,

Please go through this link very clear information about ASP.NET Application file
or Global Application File.

http://www.aspdotnet-suresh.com/2011/05/what-is-use-of-globalasax-file-in.html


Thank you

Sep 11, 2015

What is the difference b/w Debug and Trace ?


  • Tracing is the process of collecting information about the program's execution.
  • Debugging is the process of finding and fixing errors(bugs) in the program.
  • Tracing is the ability of an application to generate information about its own execution.
  • Tracing and Debugging works in a similar way, but the difference is that tracing from the 'Debug' class only works in builds with DEBUG symbol, whereas tracing from the 'Trace' class only works in builds with TRACE symbol.
  • The NameSpace, System.Diagnostics.Trace.Writeline for tracing that you want to work in debug and release builds.
  • The NameSpace, System.Diagnostics.Debug.Writeline for tracing that you want to work in debug builds only.

Sep 10, 2015

Some Important FAQ's .Net

Hi,

I would like to share some of the FAQ's in .Net

Please find the following Images






















Feb 6, 2015

How to Retrieve TOP and BOTTOM Rows Together using T-SQL

Hi,

We have to find TOP 1 & BOTTOM 1 records together.
If we use UNION ALL it will throw an error like

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword ‘UNION’.

UNION accept only one ORDER BY clause.

So,

1. For column contains characters like ABC-123

Use this syntax :

SELECT * FROM table_name
WHERE column_name IN (SELECT TOP 1 column1 FROM table_name ORDER BY column_name)
OR
column_name IN(SELECT TOP 1 column1 FROM table_name ORDER BY column_name DESC)

2. For column contains int values like 123

Use this syntax :

SELECT * FROM table_name
WHERE column_name IN (SELECT TOP 1 min(column1) FROM table_name)
OR
column_name IN(SELECT TOP 1 max(column1) FROM table_name)

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

Example :

1. For column contains characters like ABC-123



2. For column contains int values like 123



Thanks