Wednesday, July 24, 2013

Error 1064 Insert statement using MySQL Parameters (C#)

Code:
dbQuery = String.Format(@"INSERT INTO accom_temp_hotelagencies(hotel_id, agency_id, hotel_webid, desc)VALUES(?HotelId, ?AgencyId, ?HotelWebId, ?Description)");
The code above has a database field called desc which is a reserved word in
SQL as an order by criteria.

The solution is to enclose the field name desc with an acute or back quote
as shown in the code below:
Code:
dbQuery = String.Format(@"INSERT INTO accom_temp_hotelagencies(hotel_id, agency_id, hotel_webid, `desc`)VALUES(?HotelId, ?AgencyId, ?HotelWebId, ?Description)");  
Cheers!

Tuesday, July 23, 2013

LINQ slow performance in checking almost 1 million data (Optimization Problem)

I have a code below which returns an object after satisfying a given condition.
1
2
3
result = listCountryStateCollection.Find(e => (e.CountryName.ToLower().Trim() == accomTempHotel.CityProvinceCountryName[0].CountryName.ToLower().Trim())  
      && (e.StateName.Trim().ToLower() == accomTempHotel.CityProvinceCountryName[0].StateName.ToLower().Trim())  
      && (e.SuburbCityName.Trim().ToLower() == accomTempHotel.CityProvinceCountryName[0].SuburbCityName.ToLower().Trim()));  
The problem I encountered was that, it was slow in getting the desired results. After doing optimization/code checking I came up with a simple solution. The solution is not to include string manipulations in your LINQ but instead the processing should be done using variables as defined below:
1
2
3
4
5
6
string country = accomTempHotel.CityProvinceCountryName[0].CountryName.ToLower().Trim();  
 string state = accomTempHotel.CityProvinceCountryName[0].StateName.ToLower().Trim();  
 string suburb = accomTempHotel.CityProvinceCountryName[0].SuburbCityName.ToLower().Trim();  
 result = listCountryStateCollection.Find(e => (e.CountryName == country)  
                   && (e.StateName == state)  
                   && (e.SuburbCityName == suburb)); 

Greg

Tuesday, July 9, 2013

Debugging jQuery/Javascript Code not working in ASP.NET MVC 3 (VS 2010)

In my MVC 2 post here:
Debuggin jquery/javascript code,
the workaround was to isolate the javascript codes in a separate .js file. However, there's another way to add breakpoints by referring to localhost html file in the solutions explorer as stated in this website link: Debuggin javascript with IE9/Visual Studio 2010 MVC 3

Greg

Friday, July 5, 2013

ASP.NET MVC C# Razor Syntax Quick Reference (REPOST)

Here's a quick reference of razor syntax with webforms equivalent:
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx

Cheers!