Using SQL ‘LIKE’ Statement on .NET SqlDatasource for MySQL

I am back with another technical post! This time, it is with regards with the SQL ‘LIKE’ statement in SQLDatasources which are available in .NET development. Recently, I was having trouble figuring out how you can actually use a SQL statement such as

SELECT * FROM products WHERE productName LIKE ‘%Computers%’

inside a SQLDatasource in an ASP.NET project. Unlike SQL Server, MySQL does not understand the syntax if you use the ‘+’ symbol and put it this manner:

<asp:SqlDataSource ID=”SqlSearchResults” ConnectionString=”<%$ myConnString %>” ProviderName=”<%$ ConnectionStrings:myConnString.ProviderName %>” runat=”server” SelectCommand=”SELECT * FROM product WHERE productName LIKE ‘%’ + @productName + ‘%’)”>
</asp:SqlDataSource>

That is where the use of the CONCAT statement in MySQL comes to play. As the MySQL Database engine does not understand the ‘+’ symbol which we frequently use in SQL Server, CONCAT will help to replace this irregularity in MySQL. So, to get it to work, just modify the data source as follow:

<asp:SqlDataSource ID=”SqlSearchResults” ConnectionString=”<%$ myConnString %>” ProviderName=”<%$ ConnectionStrings:myConnString.ProviderName %>” runat=”server” SelectCommand=”SELECT * FROM product WHERE productName LIKE CONCAT(‘%’, @productName, ‘%’)”>
</asp:SqlDataSource>

With this, your problems with mySQL LIKE will be solved immediately! Hope this helps some people out there… ;)

Facebook

Sharing your Webpage on Facebook

With Facebook becoming a trend setter in social networking, it is hardly surprising to see websites coming up with ways to allow users to share content through it. In this post, I will show how you can easily place a Facebook sharing link and place it onto any page of yours.

To do this, firstly, you will require some basic knowledge in HTML. Open up your web page editor and just place in the following code into the location where you want the sharing link to be at:

<a name=”fb_share” type=”button_count” share_url=”www.example.com”  href=”http://www.facebook.com/sharer.php?”>Share</a>
<script src=”http://static.ak.fbcdn.net/connect.php/js/FB.Share” type=”text/javascript”></script>

Make sure you replace www.example.com with your own site URL to ensure that it works. Once successful, you should be seeing a result like this below:
Share

By clicking on it, you will be redirected to Facebook and you should be seeing a result like this:

Facebook sharing!

And that is all you need to share your site on Facebook. Will be coming up with more details on the Facebook API such as the “Like Box” coming here soon!

transform

Derek’s Tech Blog is now “Tech for Snack”!

Derek’s Tech Blog (http://derekchan84.wordpress.com) have now moved over to a brand new domain! Stay tuned for more tech news and details. For those who have been following Derek’s Tech Blog previously, be rest assured that this blog will be active in the coming months.

Will be coming right back with more yummy tech details!