Search

Apr 27, 2008

The 25 New Features in SSMS 2008

Check it out :

The 25 New Features in SSMS 2008

Mar 26, 2008

Mar 14, 2008

Cannot convert type 'System.Collections.Generic.List<

I have one problem while working with Generic collection. I am returning the generic collection of base class, which at the end assigned to child class.


List<Child> childs = SelectAll();

Here is the defination of SelectAll();


public override List<MyParent> SelectAll()

While doing this I got an error....

Cannot implicitly convert 'System.Collections.Generic.List<MyParent>' to 'System.Collections.Generic.List<Child>'

Because, the returning collection is of MyParent and I need to store it into collection of Child.

Here is the solution.

Generic collection List<> provider one Generic method called ConvertAll

ConvertAll: Converts the elements in the current List<(Of <(T>)>) to another type, and returns a list containing the converted elements.

Here is the code,

List childs = SelectAll().ConvertAll<child>(ParentToChild);

and here is the ParentToChild method.

public static Child ParentToChild(MyParent myParent)
{
return (Child)myParent;
}


Read more..

Jan 21, 2008

Passing lists to SQL Server 2005 with XML Parameters

We frequently have requirement like

Passing IDs in comma saperated value to the sql server for further processing.

Generally what we do is just create loop and get the value from it and ...

But SQL 2005 comes up with XQuery. Using this you can easly pass such type of data also some complex thing too.

For example...

DECLARE @productIds xml
SET @productIds ='<Products><id>3</id><id>6</id><id>15</id></Products>'


SELECT ParamValues.ID.value('.','VARCHAR(20)')FROM @productIds.nodes('/Products/id') as ParamValues(ID)

Which gives us the following three rows:

3
6
15

Read more..

Nov 28, 2007

How to know page validity from java script

Hello All,

I was having one requirement which is as follows.

- Once you click on submit button, the button must be disabled
- All the validator should work properly then and only then button get disabled [obvious thing]
- And the page needs to be submitted back to server as well.

I was looking for the method where I can find the page valid property or value which allow me to do what I want.

There is a property Page_IsValid in java script which let me know the validity of page. But it will always set to false first time.

So I found the solution which help me to fulfill my requirement.

Have a look at following code

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

function btnSaveClientClick(objBtn)
{
var isPageValid = Page_ClientValidate();
if(isPageValid)
{
objBtn.disabled = true;
__doPostBack(objBtn.name,'');
}
}

</script>

This is the server side control [submit button]

<asp:Button ID="btnSave" runat="server" SkinID="button_plain" OnClientClick="javascript:return btnSaveClientClick(this);" Text="Save" OnClick="btnSave_Click" />

How it works:

- On client click of save button btnSaveClientClick() method get executed with single parameter this which is button itself.
- Page_ClientValidate() method used for checking client site validation, will return true or false.
- objBtn.disabled, will disable the button because objBtn is reference to our Save Button
- And last need to postback to server, so call __doPostBack(objBtn.name,'');

That's it!

Oct 22, 2007

Web service architecture

Hello Friends,

What is webservice? What is WSDL? How it works?? and many more....

I found all the answere, its really nice topic where you can find all the answers.

Have a look at this Web service architecture delicios.

Regular Expression problem???

Hello friends,

I found good link which has almost all required regular expresions, have a look at this Regular Expressions delicios.

Sep 20, 2007

Threading in C#

C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads.

To know how its working, when to use thread etc. have a look at 'delicios'

Sep 12, 2007

Display images Directly from Memory

Hello Friends,

I was looking for functionality in which I just need to throw jpg file after changing it into memory.

One way is, save it to hard drive and then use it as target of some img tag. But this is not a good idea, so searched for such kind of logic where I can directly throw the image to client.

I used following code


//Load the bitmap image
System.Drawing.Bitmap objBitMapOriginal = new System.Drawing.Bitmap(strImagePath);
//Change the bitmap image
System.Drawing.Bitmap = ScaleAndModifyImage(objBitMapOriginal);
//Save it to response
Bitmap.Save(Response.OutputStream, ImageFormat.Gif);


But this has some problem as images saved in OutputStream I cant show any other literals or data on the same response.

Then I found a solution, First store the image in session and dynamically sets the src of image which at the end pointing to same page, on requesting that image src it throws the image which is in memory and after finishing work just flush the session.

Its fairly simple, have a look at the delicious. You can also find the code.

Sep 4, 2007

How to expire previous page

Hello all,

This is the normal problem we all are facing in Web application.

Problem comes when user use back button of browser and application start malfunctioning.

Just add following code in page load

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(0, 0, 2));
Response.Expires = 0;
Response.CacheControl = "no-cache";