A Query for MERGE with CASE in UPDATE (T-SQL)

i’ve been asked by lost of people about how to use CASE when you write a MERGE statement which is synchronizing (updating) two tables.

So here we go (a very basic example which sync the quantity field in the Products table):

-- DELETES THE DUPLICATES IF ANY! (THIS IS A MUST WHEN YOU USE MERGE)
DELETE everything FROM (
SELECT *, rownum = ROW_NUMBER() OVER (PARTITION BY ItemID ORDER BY ItemID)
FROM QuantityUpdates
) everything
WHERE rownum > 1;
 
-- please notice that you can also use group by to prevent duplicate rows !!!
 
MERGE INTO
Products AS Prod
USING
QuantityUpdates AS Qty
ON
Prod.ItemID = Qty.ItemID
WHEN
MATCHED
THEN UPDATE SET
QtyInStock = Qty.QtyInStock,
UpdatedDateStamp = GETDATE(),
Discontinued = CASE WHEN Qty.QtyInStock > 0 THEN 0 ELSE 1 END;

Voila! Hope this helps someone

Windows 8 First Impressions

Windows 8 - First Impressions

Windows 8 – First Impressions

Sometime about a month ago, I asked my dear friend what he thinks about the new Microsoft Operating System – Windows 8?
Here’s what he told me: Read the rest of this entry »

Tags: , , ,

Why Your New Windows 8 Freezes up (Possible FIX)?

Google Chrome vs. Windows 8Wonder why your recently installed Operating System (Windows 8) freezes up?

Do you have a Google Chrome installed on your computer?

If you do please go ahead and uninstall it. Well at least, it worked for me.

Now my PC works flawlessly!

Hope this helps anyone else having the same problem :)

Tags: , , ,

Merry Christmas and Happy New Year 2013

May this lovely Christmas season bring you delights in all possible forms.
May you receive love in abundance and joy that lasts throughout this season.
Merry Christmas and Happy New Year to you and your loved ones!

marry christmas and happy new year 2013

Merry Christmas and Happy New Year 2013

Godaddy Renew coupons 2012 (October)

I used them both for renewing my domains and they both worked fine:

FB30TLD
GD50BBPD5

Suppress Uppercase Conversion in Visual Studio 2012

As you’ve already noticed, by default all the Main Menu items in your Visual Studio 2012 are uppercase.

To fix this (to disable/suppress uppercase conversion) you have to create a new DWORD in the Registry Editor.

1. run RegEdit.exe (type RegEdit in the Run)

2. Expand the HKEY_CURRENT_USER as shown on the image below

Registry Editor

Registry Editor

3. Right-click General node and then select New -> DWORD (32-bit) Value as shown on the image below.

Context Menu

Context Menu

4. Name it “SuppressUppercaseConversion” and click OK!

5. Double click the newly created value and set the Value data to 1 (as shown on the image below)

Value data

Value data

Voila. Now re-open your Visual Studio 2012 and your Menu items will appear like in the previous version of your favorite IDE

Fix the uppercase menu items in VS 2012

VS 2012 Main Menu uppercase items

Hope this helps to someone! Cheers

Visual Studio – Shortcuts for code regions

CTRL + M + O will collapse all.

CTRL + M + L will expand all.

CTRL + M + P will expand all and disable outlining.

CTRL + M + M will collapse/expand the current section.

A generic error occurred in GDI+ (Possible Solution)

I guess you’ve read about permissions thing which is that your application doesn’t have a write permission on some directory. But sometimes it can be simply a missing directory. Yeah it did happen to me today. I just found out that VS compiler excluded an empty folder from the pre-compiled version. As soon as i copied the precompiled version i started getting “A generic error occurred in GDI+” error. So next time just double check if missing folder is your problem. Find the code that deals with the GDI+ and be sure that your paths match existing folder(s).

Hope this helps to someone

How to get rid of the XML Parsing Error

XML Parsing Error

XML Parsing Error

I just want to share a possible fix for this odd error. In my case it was a silly if statement in which i decide if MyPanel control should be rendered or not. However i missed the name of the panel control so i ended up with this XML Parsing Error. After i while i figured out that i have an error in the code-behind that looked like the following:

If condition = True Then
   MyPanel.Visible = True
Else
   Visible = False
End Try

Once i changed to the below it worked like a charm.

If condition = True Then
   MyPanel.Visible = True
Else
   MyPanel.Visible = False
End Try

Hope this helps to someone at least

WebsiteSpark Unsubscribe – is it possible?

I would say it is not. Why? Well, because they send you a broken unsubscribe links.
Of course i did that long time ago in the account options (currently cancelled) but it kept sending me various emails.
Most of them if not all, do not contain an unsubscribe link. And now they finally added the link at the footer but it does not work.
If you click it does nothing as it starts with “file:///C%7C/Users/Stephen/Desktop/Projects” etc.
This is the whole link:
Read the rest of this entry »

How to add and watch movie on your PSP

watch movie on your PSP

watch movie on your PSP

I bought it several months ago. Mainly for my kids to play the games on it. But, last night they ask me if they can watch a cartoon on it. I googled and found a tons of tutorials about how to convert movie to psp format which is MP4. So far so good. I converted the Rio DvdRip to MP4. I connected the PSP with my laptop hoping that i will just copy the converted cartoon to the stick and it will work. But i was wrong. I put it to the root of the memory stick but it didn’t work at all. The PSP was not able to find the movie. Then i googled again and found a lots of tutorials about how to put movie on your PSP. They all suggested the same which is creating a two folders MP_ROOT and 100MNV01 inside it. Some of them even suggested that i name the files M4V10001.MP4, M4V10001.MP4 etc. respectively.  None of these worked for me. Rather i tested something pretty silly as it seemed from beginning. Meaning, i created a brand new folder named VIDEO in the root of the memory stick and i put the converted file as is Rio 2011.mp4. Final result X:\VIDEO\Rio 2011.mp4 !!! Voila!

It worked like a charm. My kids were very happy because of that. Hopefully someone else will find this useful too.

Change Visual Studio 2010 Development Server (Cassini) Port Number

You guys probably know that Visual Studio includes a lightweight ASP.NET development server which is an enhanced version of Cassini.

You may have noticed or heard, people want to change the port number of it so here we go;

1. Rigth click your website in Solution Explorer window and select Properties from the context menu (Alt + Enter). Read the rest of this entry »

RadControls For ASP.NET AJAX 2011 Q1

RadControl for ASP.NET AJAX
Hello Guys,

Before I continue I would like to mention that I deleted the previous version of this review which was much longer, and more eloquent but then I realized that it is not necessary at all. Simplified, the Telerik controls are a must for every serious asp.net developer.

Ok here we go:

I am fairly new to Telerik stuff and I am wondering where to start really. Nevertheless I am very pleasantly surprised by the overall look and performance.

Actually I have NOT been so pleasantly surprised for longer. I cannot resist mentioning that I love its ease of use and above all, easy of install.

Well, usually you use the standard installation (.MSI Setup) but, rather you can DL the libraries and simply add a reference to DLL’s . Voila! You are all set up to use RadControls for ASP.NET AJAX.

It can’t be simpler, right? Read the rest of this entry »

ASP.NET versus ASP Classic

ASP.NET is SuperiorIf you often revise your decision to go for .NET. then let me tell you a few things about ASP.NET.

By the way, if I have to be an ASP developer starting now I would rather work as a cleaner in a public WC indeed.

Here we go:  Read the rest of this entry »

How to Remove unused Application Pools using ServerManager Class

Public Sub RemoveUnusedApplicationPools()
        Dim manager As New ServerManager
        Dim AppPools As New List(Of String)
        ' fill the list with all pools
        For Each apppool As ApplicationPool In manager.ApplicationPools
            AppPools.Add(apppool.Name)
        Next
 
        ' if it's used remove from the total list
        For Each website As Site In manager.Sites
            For Each app As Application In website.Applications
                AppPools.Remove(app.ApplicationPoolName)
            Next
        Next
 
        ' remove the unused pools
        For Each unusedApplicationPool As String In AppPools
            Dim apppool As ApplicationPool = manager.ApplicationPools(unusedApplicationPool)
            manager.ApplicationPools.Remove(apppool)
        Next
 
        ' call the commitchanges method
        manager.CommitChanges()
        manager.Dispose()
    End Sub

DevExpress How to Enable Form Skins

DevExpress WinForm Skins

DevExpress WinForm Skins

I just realized something about the Skins. Actually it is not enough to add XtraForm (DevExpress Form) to your project and then drag & drop DefaultLookAndFeel. Oh no! If you want your forms appear with skins applied you have to do something more.

No big deal, but if you don’t know this you’ll probably struggle with it.  Read the rest of this entry »

Microsoft Visual Studio 2010 Service Pack 1

Visual Studio 2010 SP1

Visual Studio 2010 SP1

Hello guys. I was wondering what do you think about the final version of the Visual Studio 2010 Service Pack 1?

I found that a lots of developers react negatively. Many of them even rolling back the SP1. They talk about incompatibilities with the SP1 release.

Please share your experience and opinion about the new Service Pack!!! Thanks

Download Link

MSDN Subscribers Here

A regex that matches all credit cards

Regular Expression For Credit Card Numbers

Regular Expression For Credit Cards

This is a regular expression that validates all credit card numbers including VISA, MASTER, AMEX and DISCOVERY! ^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$

<asp:RegularExpressionValidator ID="CreditCardValidator" runat="server" 
   ControlToValidate="CreditCardNumber" Display="Static" 
   ErrorMessage="Please enter valid card number" 
   ValidationExpression="^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$"  
  ValidationGroup="CustomSignup" Text="*" />

Conversion from Currency into English Words

Currency into Words

Currency into Words

I often need to convert the amounts into words when i create reports, checks and stuff. I found that the following recursive functions do the job perfectly. Most of the examples you can find out there are too long and confusing. This one seems to be shortest and str8 forward. Please check it out:

Read the rest of this entry »

Happy New Year 2011

Happy New Year 2011

Happy New Year 2011

 

 

may the New Year begin on a prosperous note! To all ASP.NET developers and their families! Cheers!!!

 

 

SQL Rounding Up Issue

often people complain about rounding up decimal values. The first question they ask is why SQL Server truncates the decimals which is silly because it happens in the code-behind.

For instance, say that you have a field of decimal datatype with precision 5 and scale 2 – decimal(5, 2)
Now if you don’t define precision of the output parameter the value will be rounded up. e.g. 0.99 becomes 1

CREATE PROCEDURE mySP
(
     @MyDecValue decimal(5, 2) output
)
AS
     SELECT @MyDecValue = MyDecField FROM MyTable WHERE Foo=1
Dim command As SqlCommand = connection.CreateCommand
command.CommandText = "mySp"
command.Parameters.Add("@MyDecValue", SqlDbType.Decimal, 5).Direction = Output

now if you execute the command the value will be as mentioned rounded up .. meaning, 0.99 becomes 1

You can solve it if you Define the precision and scale of the parameter e.g.

Dim command As SqlCommand = connection.CreateCommand
command.CommandText = "mySp"
Dim decimalsparam As New SqlParameter
decimalsparam.Direction = ParameterDirection.Output
decimalsparam.ParameterName = "@MyDecValue"
decimalsparam.Precision = 5
decimalsparam.Scale = 2
decimalsparam.Size = 5
 
command.Parameters.Add(decimalsparam)
command.ExecuteNonQuery()

DXperience v2010 vol 2 Review

Hi guys, this is my second review of these controls, and it will be quite different than the first.

A few months ago I was engaged by a client to develop a web based application. He asked me (I guess they all ask the same) to make it good looking and attractive. The first thing I thought of when I heard this was “I must renew my DXperience subscription”. And now I am glad I did that.

Before I continue, I would like to say something to those readers who are totally new to DXperience. Guys, we all know that one of the more frustrating things for the ASP.NET developers is designing the good looking application. Well folks, your troubles are over! The DXperience takes much of the agony out of developing and designing an outstanding web application.

Here we go! Read the rest of this entry »

AddHandler Statement

A very basic tutorial on AddHandler Statement. In this project we used it to prevent a non-numerical values to be entered in the textbox controls.

You may also choose the event handler for each control from Designer.
Just select all the controls you want to add the same Event Handler to.
Then from the Events view in Properties panel double click KeyPress and finally add the code that you want to apply to the selected controls.
Note: This approach can’t be used always instead AddHandler statement.

Programmers and the Recession

Programmers And The RecessionHaving a permanent job is priceless these days (you know, recession and stuff). But, it’s sort of limitation for your creativity. Working for you is much better. You often work on projects of your choice, set your own hours, and enjoy the flexibility to take a break whenever you want.

However to afford that, you must be very good if not the best at what are you doing. e.g. .NET programming, Website Design etc. I had luck with all of the above so now i am doing pretty good having a standard income on monthly basis plus I work on other projects as a freelancer.
Read the rest of this entry »

GoDaddy Promo Codes List (Working One)

I registered a few domains at godaddy a while back and also i bought new hosting plan from the same company.

The interesting thing is that prior to Checkout i reminded myself of the suggestion of my friend who actually told me about godaddy coupons.

I thought it is not big deal so i was always ignoring his appeals. lol

Well, this time i decided to follow his advice so i opened his email with the newest godaddy coupons.

As soon as i entered BTPS7 the grand total was drastically decreased by whole 20%.

Wow … i just saved about $40 which is not a low amount at all. I could buy some extra domains with this money. And i did so. I spent that money buying 6 extra domains. So cool!!!

From now i will always use the promo codes when i shop online!

So, here’s a list of a few codes for 2009
Read the rest of this entry »

Tags: ,

Merry Christmas and Happy New Year !!!

Happy Hollidays

Happy Hollidays

May this Christmas be bright and cheerful and may the New Year begin on a prosperous note! To all ASP.NET developers and their families! Cheers!!! :)

GetAFreelancer.com Ripoff Report

Rip Off

Rip Off

Hello Guys,

Recently i had very bad experience begging a bloody company for my own money.
Finally i want to tell you to stay away from this company and their site www.getafreelancer.com.
You should always deal with people whose addresses are real, customer service real and you can get a live person on the phone.
Yeah, that’s true that GAF has not phone number to be called. It sucks, isn’t it?
They have a LIVE SUPPORT button on their site but all it does is take you to their email form so their support is not live particularly when they take days on end to answer, if they bother to answer at all.

In addition, www.getafreelancer.com is in the habit of suspending members when their accounts have money in them. This has recently happened to me and I am aware of others that have gone through the same problem. In addition to this they will ask for ID of proof of Country. When you provide them with the pertinent information where they can see the ID. clearly but not to the point where it can be duplicated they want more. This doesn’t make any sense if its just for proof of country.
This is obviously something that this Company has been getting away with for some time. They are holding money not only in peoples personal accounts of money they have earned, but also in escrow.
Its time people took legal action. You can start by laying a complaint with the internet crime complaint center. There are also other legal sites listed on the internet as well that you can lodge a complaint with.

Strongly recommended!

Stay away from this company and their site www.getafreelancer.com.
Always deal with people whose addresses are real, customer service real and you can get a live person on the phone.
Yeah, that’s true that GAF has not phone number to be called. It sucks, isn’t it?
They have a LIVE SUPPORT button on their site but all it does is take you to their email form so their support is not live particularly when they take days on end to answer, if they bother to answer at all.

Tags:

ASP.NET Exception – Invalid postback or callback argument

Invalid postback or callback argument

Invalid postback or callback argument

I’ve read many different suggestions for the Invalid postback or callback argument exception but, most of them do not work.
Some people will suggest to add your code inside If Not Page.IsPostBack Then block, other will tell you to set EnableEventValidation to false which is not serious at all. Even the compiler suggests ClientScriptManager.RegisterForEventValidation method but in most of the situations these will not work.

One is for certain: This specific exception is mostly thrown when you use a Master page!!!

Add the same javascript attributes to the very same server control out of the master page and you’ll see that it is working just fine.
Read the rest of this entry »

Bind DataList to DataView Without Using Database

Bind Datalist without DB

Bind Datalist without DB

This is going to be pretty easy so i will not bother you explaining things.
Just Download the Code Sample (sample images included) and you will figure out the rest of it, analyzing the code.
Generally speaking, it gets all *.jpg images from the given folder and display in the DataList control.


Live Example For Binding DataList Without Database (List of Images)

The Source Code Can be Downloaded From Here

Force ASP.NET Page to Use secure HTTP (https) with SSL/TLS

Force ASP.NET to use HTTPS

Force ASP.NET to use HTTPS

Sometimes we want to provide encryption and secure identification of the server creating a secure channel over an insecure network.
In that case we need HTTPS connection which ensures reasonable protection e.g. for payment transactions.

 

Ok let’s see how this thing works.

Say that your page is as follows: http://www.domain.com/yourpage.aspx
Ok, just add this code inside Load Event Handler and voila! That’s it!

 

If Not Request.IsSecureConnection Then
   Response.Redirect("https://www.domain.com/yourpage.aspx ")
End If

 

Nobody gives FREE

Msn Generous Offer

Msn Generous Offer

I just ran my MSN Live Messenger and i was offered to download a free themes for its 10th Birthday.

Ok althrough i never believed in a free stuff this time i said what a hell.

As soon as i clicked the Download button i was offered to download Internet Explorer 8 and immediately after that i received another dialog which was suggesting me to use Bing as my default browser and to make MSN my homepage.

I mean it’s a pretty bad trade. I get only few themes that most probably i will never use and in return they want me to to use IE8 (instead firefox), Bing (instead google) and to make MSN my homepage (instead google as well).

Well thanks for the generous offer but, i really don’t need your FREE things.

How to create and consume an ASP.NET WebService

Although this is a very basic example (Hello World) of Web Service,  it should be enough to get an idea about how it works.

A picture is worth a thousand words!

Please send your comments if my WebService video tutorial is sort of blurred or something. Thanks

Tags: ,

My first cup of morning coffee

This is where i am drinking my first cup of morning coffee. It is a coffee bar located near me. Just 100 m from my apartment.

Btw, i do not smoke. :) It is the guy behind me!

Google’s New Operating System (Chrome OS)

Google Operating System

Google Operating System

As you know Google announced a new OS called Chrome which is primarily intended and targeted for the netbooks.

However, i want to notice that if Google doesn’t find a way to run ALL (literally all) windows software applications on the new operating system it is going to be just one more Linux distribution.

If the new Chrome OS is able to run MS Office, Visual Studio and SQL Server it will become a serious competition to the Windows. Otherwise as mentioned it will end up as one more Linux distro.

Tags: , , ,

Things I hate about VB.NET

Visual Basic .NET

Visual Basic .NET

1. I hate VB.NET because it doesn’t support block comments. Block comments are very useful for comment out large sections of code. Even T-SQL support block comments! It’s so sad and i need it on daily basis when i am testing something and large section of code should be commented out. I have to use Comment Selection Ctrl+c, Ctrl+k instead.

To be continued…

Bind ListView to DataTable

This is a very basic example to show that binding ListView is really easy.
For this tutorial i created a new table named Members:

Table Members (Structure)

Table Members (Structure)


Read the rest of this entry »

Tags:

Send e-mail from ASP.NET

Send E-Mail (ASP.NET)

Send E-Mail (ASP.NET)

Hi Ronan,

this should help you i hope.

Anyway, it shouldn’t be anything complicated so we could start with the code immediately.

 

Read the rest of this entry »

Roger’s record 15th Grand Slam Title

Roger Federer's 15th Grand Slam

Roger Federer's 15th Grand Slam

Congratulations Roger! Keep up the good work :)

It was a very enjoyable match and I’m truly impressed with Andy Roddick.

He played the best match I’ve ever seen him play today.

Big Thanks to both of you guys!

Happy Fourth of July

Happy Fourth of July

Happy Fourth of July

Today is Independence Day also known as 4th of July which is the birthday of the United States of America.

On this day, people of United States celebrate their freedom commemorating the courage and faith of their founding fathers in their pursuit of liberty.

So happy Fourth of July to all  American ASP.NET and VB.NET developers including all My Friends in USA !!!

Only Bernard Madoff ?

Bernard Madoff

Bernard Madoff

I refuse to believe that Madoff is the one and only who is responsible for the new world economic crisis.

Of course he has to fully take responsibility for what he has done but, sentencing only one man to 150 years is NOT a guarantee that it will not happen again?

Rather, we should find out, who endorsed Madoff … ?

I am aware that American justice works in strange ways but, this is too much already.

I am quite sure there must be some people that knew all the time about the Madoff’s tricks and that he was braking the law but none wanted to tell anything because they were probably all involved in.

Otherwise i have no explanation for it !!!

Kulrom