Facebook Twitter Delicious Stumble Upon
0 comments

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute 
                           '{ "@id": 1001, "@name": "Sony", "edu": "MCA" }'
Usually we do use alert(data.edu); to get the values but when @ is with attribute then use the bellow code

 var attName = data['@id'];
 alert(attName);

      or

 var att = '@name';
 var attID = data[att];

 alert(data.edu);




Tags: @ in json, @ symbol in json response, Parsing JSON with @ symbol in it.
0 comments

Using of BULK INSERT in Sql Server

Using of BULK INSERT 

STEP 1: Create a text file the name STUDENTS_LIST.txt and add the bellow data

1,RAJIV,M.S
2,VINAY KUMAR,B.A
3,HANU,M.B.A
4,ARUN,M.Sc

STEP 2: Create a table using bellow statment

CREATE TABLE #STUDENT(ID INT, [NAME] NVARCHAR(50), EDUCATION NVARCHAR(20))

STEP 3: Now use the Bulk Insert Statement

BULK INSERT #STUDENT
FROM 'D:\STUDENTS_LIST.txt'
WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )

STEP 4: Check the table using bellow query

SELECT * FROM #STUDENT

DROP TABLE #STUDENT


Tags: BULK INSERT, Insert, Sql Server, SQL, Query
0 comments

How to bind the selected value of a DropDownList

// Select * from Countries
// Select CustID,CountryID from Customers where CustID=1
DataSet ds = new DataSet();
da.Fill(ds, "Countries");
ddl.DataSource = ds.Tables[0];
ddl.DataTextField = "CountryName";
ddl.DataValueField = "CountryID";
ddl.SelectedValue = ds.Tables[1].Rows[0]["CountryID"].ToString();
ddl.DataBind();

O/p:    

Tags: asp.net, binding, selected value, data base
0 comments

Sql Server: CTAS Create table as select


Creating table from another data copy only the snytax but not the data

SELECT * FROM Customers

SELECT * INTO ImpCustomers FROM Customers WHERE 1=2

SELECT * FROM ImpCustomers

O/p:















DROP TABLE ImpCustomers 

Tags: Sql Server: CTAS Create table as select,Create, Copy
0 comments

Getting the Rows from DB in page wise using Row_Number in SQL Server

Create table #States(StateID INT,StateName NVARCHAR(20))
INSERT INTO #States
SELECT 1,'California' UNION
SELECT 2,'Albama' UNION
SELECT 3,'Alaska' UNION
SELECT 4,'Arizona' UNION
SELECT 5,'Florida' UNION
SELECT 6,'Hawaii' UNION
SELECT 7,'Montana' UNION
SELECT 8,'Indiana' UNION
SELECT 9,'Lowa' UNION
SELECT 10,'New York' UNION
SELECT 11,'New Mexico' UNION
SELECT 12,'Texas' UNION
SELECT 13,'Virginia' UNION
SELECT 14,'South Carolina' UNION
SELECT 15,'Washington'


SELECT * FROM #States
  

Create the Procedure like

Create Proc GetRecords(@pageNo int=1,@pageSize int)
as begin
Select StateID,StateName from
(Select Row_Number() over (Order By StateID) SNO,StateID,StateName from #States)S
Where S.SNO Between ((@pageNo-1)*@pageSize)+1 and @pageNo*@pageSize
end

Execution:-

exec GetRecords 1,4        --1 is page number & 4 is page size
exec GetRecords 2,4
exec GetRecords 3,4
exec GetRecords 4,4

o/p:
DROP TABLE #States

Tag: Using Row_Number in SQL Server finding records