Monday, June 2, 2014

How to remove the special characters from the string in the SQL Server

Step 1:- Before starting to know this we have to learn one function the Sql server

PATINDEX()

Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types

Example 1 Write the below sentences

SELECT PATINDEX('%lokeshasp%', 'Have You ever seen this lokeshasp.blogspot.com ');
--This is also used for the first get the char index and the word index

OutPut:-

25

Example 2

DECLARE @GetIndex INT,@string varchar(100)
SET @string='welcome-to''lokeshasp.blogspot.com#$'
SET @GetIndex = PATINDEX('%[^a-zA-Z0-9 ]%', @string)
WHILE @GetIndex > 0
BEGIN
SET @string = STUFF(@string, @GetIndex, 1, ' ' )
SET @GetIndex = PATINDEX('%[^a-zA-Z0-9 ]%', @string)
END
SELECT @string

OutPut :-


welcome to lokeshasp blogspot com  
Read More »

Sunday, June 1, 2014

How to remove the long space in the sentence using SQL SERVER

Step 1:- Example sentence

'Hello               Welcome   to   lokeshasp.blogspot.com'
Step2:-Write the below code
DECLARE @str varchar(150)

SET @str='Hello               Welcome   to   lokeshasp.blogspot.com'

Select REPLACE(REPLACE(REPLACE(@str,' ','[]'),'][',''),'[]',' ')
OutPut :-
Hello Welcome to lokeshasp.blogspot.com

Explanation
DECLARE @str varchar(150)

SET @str='Hello               Welcome   to   lokeshasp.blogspot.com'

Select REPLACE(@str,' ','{}')

O/P:-  Hello{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}Welcome{}{}{}to{}{}{}lokeshasp.blogspot.com
Select REPLACE(REPLACE(@str,' ','{}'),'}{','')

O/P:-   Hello{}Welcome{}to{}lokeshasp.blogspot.com
Select REPLACE(REPLACE(REPLACE(@str,' ','{}'),'}{',''),'{}',' ')

O/P:-   Hello Welcome to lokeshasp.blogspot.com

Full Code
DECLARE @str varchar(150)
SET @str='Hello               Welcome   to   lokeshasp.blogspot.com'
Select REPLACE(@str,' ','{}')
Select REPLACE(REPLACE(@str,' ','{}'),'}{','')
Select REPLACE(REPLACE(REPLACE(@str,' ','{}'),'}{',''),'{}',' ')


Read More »

Thursday, May 29, 2014

Working With __doPostBack Jquery Function In The Asp.Net C#

Introduction

In this article we are going to learn the topic of how to post back the dropdown selected change without changing the property of Autopostback=”true” .

For this we are going to call the method at the time of onchange event OnChange="dropDownChange();"

In this method we write the call back method with parameter condition like
__doPostBack('pnlGrid', strUser)

Coding

Write this code

In Aspx Source File

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">


Read More »

Get The Specific Column From The Data Table Using Asp.Net C#

Step 1:- Creating the dynamic data table

DataTable dt = new DataTable();
dt.Columns.Add("UserId", typeof(int));
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Education", typeof(string));
dt.Rows.Add(1, "Lokesh", "B.Tech");
dt.Rows.Add(2, "Vijay", "Msc");
dt.Rows.Add(3, "Balaji", "MS");
dt.Rows.Add(4, "Charan", "B.Tech");
dt.Rows.Add(5, "Durga", "MD");
dt.Rows.Add(6, "Shiva", "B.Tech");
dt.Rows.Add(7, "Venkat", "CA");

Step 2:- By using the DefaultView Key word get the specific column from the existing the data table

DataTable dtDistinct = dt.DefaultView.ToTable(true, "UserName");

It will return only the "UserName” Column details


Read More »

Get the Specific Row From the Data Table using LINQ in Asp.Net

Step 1:- Create One dynamic datatable

DataTable dt = new DataTable();
dt.Columns.Add("UserId", typeof(int));
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Education", typeof(string));
dt.Rows.Add(1, "Lokesh", "B.Tech");
dt.Rows.Add(2, "Vijay", "Msc");
dt.Rows.Add(3, "Balaji", "MS");
dt.Rows.Add(4, "Charan", "B.Tech");
dt.Rows.Add(5, "Durga", "MD");
dt.Rows.Add(6, "Shiva", "B.Tech");
dt.Rows.Add(7, "Venkat", "CA");

This is the LINQ code for getting the specific row based on the Userid

var results = (from myRow in dt.AsEnumerable()
where myRow.Field<int>("UserId") == Convert.ToInt16(“1”)
                               select myRow).CopyToDataTable();

GridView1.DataSource = results;
GridView1.DataBind();


Read More »