Posts

Showing posts from August, 2010

LinqDatasource A Great Control for declarative programming

Image
I have used data source control many times and its great it provides us great features for declarative binding. LinqDataSource Control is a great control and it allows us to bind linq queries without writing any code declaratively. Let’s create a example in that example I am not going to write a single line of code and we are going to create view,Update and Delete functionality.So first we need a table which will have data. So, I am going to use the same table which I have used in my old posts. Below is the table structure for this example.Let’s insert some data for that table structure. I have already inserted it in previous example. Just like below.Now, To bind a linqdatasource we need a Linq-To-SQL Data context class Let’s create it via Project->Right Click->Add New Item –>Go to data tab->Linq-To-SQL classes Just like following.After that I have just dragged user data to my data context just like following.
After creating Our Linq-To-SQL Classes Let’s just Add the A grid…

Calling an asp.net web service from jQuery

Image
As I have post it in earlier post that jQuery is one of most popular JavaScript library in the world amongst web developers Lets take a example calling ASP.NET web service with jQuery . You will see at the end of the example that how easy it is to call a web service from the jQuery.

Let’s create a simple Hello World web service. Go to your project right click->Add –> New Item and select web service and add a web service like following.

Now modify the code of web service like following.

[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class HelloWorld : System.Web.Services.WebService { [WebMethod] public string PrintMessage() { return "Hello World..This is from webservice"; } }
Here please make sure that […

jQuery- JavaScript Library Write less do more

Image
This is introductory post jQuery an open source JavaScript library. I know what you guys thinking and I also know that jQuery does not required introduction. It is so much popular and most of web developers whether they are developing using asp.net,php,Jsp or any language on web they are using jQuery but this post is for who is not aware of it and or they are new to the web based programming. We all are using JavaScript for client side scripting language almost 95% percentage of web application uses JavaScript as client script. We do lots of things with JavaScript right from the alerts to validation of controls to animation and now days we calling web services from JavaScript and fetching server side data also and rendering them into browser. If you are using JavaScript then you are following some patterns like selecting a element on and then perform some operation on that element on client side like do validation of controls or changing the style sheet of that element or animating …

Using Let Keyword in Linq

Image
I am using Linq-To-Object in my current project to remove some extra loops and I have found one of the great keyword in Linq called ‘Let’. Let keyword provides facility to declare a temporary variable inside the Linq Query.We can assign the result of manipulation to temporary variable inside query and we can use that temporary variable to another manipulation.Let’s take a simple example of Linq query I am using an integer array to find square and after finding the square of the integer value I will use let keyword to find square value which are greater then 20. Here is the my query for that.protected void Page_Load(object sender, EventArgs e)
{

int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
var Result = from i in intArray
let square = i * i
where square>20
select square;
foreach (int i in Result)
{
Response.Write(i.ToString());
Response.Write("\n");

Entity Framework 4.0- Bind Stored Procedure with Result Entity class

Image
Microsoft Entity Framework version 4.0 is a brand new ORM(Object Relational Mapper) from Microsoft. It’s provides now some new features which are not there in the earlier version of Entity framework. Let’s walk through a simple example of a new features which will create a new Entity class based on stored procedure result. We will use same table for this example for which they have used earlier for Linq Binding with Custom Entity.Below is the table which have simple fields like first name,last name etc.Let’s insert some data like following.Below is the stored procedure which I am going to use for this example which will simply fetch data from the table.CREATE PROCEDURE dbo.GetAllUsers AS SET NOCOUNT ON SELECT UserId, UserName, FirstName, LastName, FirstName + ' ' + LastName AS [FullName] FROM dbo.Users Now let’s create Entity model class just like below via Project->Add New Item->Go to Data tab and then select ADO.NET Entity Data Model.

Once you click add a dialog box w…

Binding A Custom Entity Class to stored procedure using Linq-To-SQL

Image
I have already written several post about Linq its a great ORM that we can use in various way. The purpose of this post to demonstrate How we can bind custom entity to stored procedure result with use of Linq-To-SQL. Let’s go through it and you will realize that how easy it will be to bind a Custom Entity to Stored Procedure result.Let’s first create a simple table to which will hold the user data. It will contain four field like UserId,UserName,FirstName and LastName like following.Now let’s insert some data into the table like following. Now let’s create a stored procedure which will return the table data and a new field called Full Name like following. Here full name is a combination of first name and last name CREATE PROCEDURE dbo.GetAllUsers AS SET NOCOUNT ON SELECT UserId, UserName, FirstName, LastName, FirstName + ' ' + LastName AS [FullName] FROM dbo.Users After creating a stored procedure it time to create a Linq-To-SQL Right Click Project->Add New Item and Go T…

Visual Studio –>Add Database –> Named pipe Provider Error for SQL Server

Image
Recently I have been working on a article for my blog for that I just tried to add a database file on my solution with visual studio and I have received following error.An error has occurred while establishing a connection to the server.
(provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)
An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2008, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 1326)After checking my configuration I have found that in my machine there was more then one instance of SQL Server and the Default Instance was not properly configured and that’s why I am getting this error. This error was occurred because my Default Instance of SQL Server Express was not…

TSQL Challenges on beyondrelational.com

Image
My friend and Guide Jacob Sebastian who is an Microsoft SQL Server MVP running a very popular series of TSQL on his site beyondrelational.com. If you know something about SQL Server then this challenge is for you. And if you are master of SQL then this challenge is for you to test you knowledge. If you have some time and If you want to test you knowledge or you want enhance your knowledge challenge then please spare some time to take it. Here is link for that.http://beyondrelational.com/blogs/tc/archive/2010/07/26/tsql-challenge-35-find-the-total-number-of-full-attendees-in-each-24-hop-session.aspxCurrently he is running TSQL Challenge Number 35 which is about fine number full attendee for a conference.Technorati Tags: ,