Monday, February 25, 2013

Object Oriented JavaScript

   Some basic concepts in Object oriented JavaScript’s are discussed below
  <input type="button" id="btnCheck" onclick="GetData();" />

We have a button that calls a client side function GetData() on its click.

<script language="javascript" type="text/javascript">

    function GetData() {

        testBL.getTestData();

//calling function in testBLL.js
//with object testBL and function getTestData()
    }
    
   
    </script>


Now we will have to create testBLL.js

In this we can create the methods and expose those methods


Code in testBLL.js:


var testBL = new function () {

    ObjectOreientedScripttest = function () {

//you can write your function code here

    },


getTestDataByDate = function () {
   

//you can write your function code here


}



    return {

        testForObjectOreientedScript:ObjectOreientedScripttest ,
        getTestData: getTestDataByDate
    }

} ();

This return statement is mandatory to expose those methods.

For eg:
Inside the return statement we have the below statements

 getTestData: getTestDataByDate

 
getTestDataByDate  is the function we have created in the testBLL.js and second one getTestData is the name that we get when we are calling the method.

 I.e.    testBL.getTestData();


testBL is the variable name that we used for testBLL.js functions(refer first line testBLL.js)



Friday, January 11, 2013

Passing Table-valued Parameter to Stored procedure

Table-Valued Parameters:
                Table valued parameter provide the developer an easy way to work with Multiple rows and data. Table-Valued parameters were introduced in Sql Server 2008
Syntax:
create type TypeName AS TABLE(

column1 type,
column2 type...

)

Eg: create type EmployeeDetails AS TABLE(

RowID int,
EmployeeName varchar(25),
EmployeeTitle varchar(30),
EmployeeAge int
)
In the above eg,
We are creating a table valued type for EmployeeDetails,this table valued type replicate the same of a Sql Table.

Manipulation on Table Valued Type:

     Table valued parameters are same as Sql Table.

You can insert into table valued Type as same like how you insert value to a table.


Declare @EmployeeDt as EmployeeDetails
insert into @EmployeeDt values(1,'George','Manager',24)
insert into @EmployeeDt values(2,'Rahul','Tester',38)
You can select the entire data from that table-valued type by
a single select statement.

select * from @EmployeeDt



Passing Table-Valued type to StoredProcedure:
create procedure SaveEmployeeDetails
@EmployeeDt as EmployeeDetails Readonly
AS
Begin
--selecting from table valued parameter and inserting into table --in a single strech
insert into Tbl_Employee(ID,EmployeeName ,EmployeeTitle,EmployeeAge)
select  RowID,EmployeeName ,EmployeeTitle,EmployeeAge
from @EmployeeDt
End



C# Code:
SqlDatabase sqlConn;
DbCommand dbcmd;
SqlConn = new SqlDatabase ("your Connection string here");
dbcmd = sqlConn.GetStoredProcCommand(SaveEmployeeDetails);
dbcmd.CommandType = CommandType.StoredProcedure;
sqlConn.AddInParameter(dbcmd, "@EmployeeDt", SqlDbType.Structured, dt);
              
 sqlConn.ExecuteNonQuery (dbcmd);