Posts

Donate

SQL Server Function To Return Amount As Decimal

Here's a simple function that will return the freight amount in decimal format. use Your_Database_Name if object_id (N 'dbo.getFreightValue' , N 'FN' ) is not null drop function getFreightValue go create function getFreightValue ( @salesID nvarchar(50) ) returns decimal(10,2) as begin declare @ result varchar(50) set @ result = ( select Freight from dbo.Orders where OrderID = @salesID ) return @ result end go -- run function -- select dbo.getSomeValue(10248) as freight_value; Cheers!

Castle Windsor - Could Not Perform FindAll() For (Model) Using ActiveRecordBase in Castle.ActiveRecord ORM

When running a simple asp.net mvc project, I encountered an error which states the Model.FindAll() could not be performed. Model is a class that maps to a database table. After tracing my codes, I found out that I have mispelled the database name in my web.config as specified below: <add key= "connection.connection_string" value= "Data Source=MyComputerStation\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Blogs.mdf;Integrated Security=True;User Instance=True" /> What I did was change the database name from Blogs to Blog . That's it! :) Greg

How To Set Connection String In Properties.Settings Of ASP.NET Class Library Project

Image
Usually, we set an asp.net connection string directly in the app.config. However, we can also do it Properties.Settings. As soon as we saved the name and value, it will reflect in the app.config. Here's a sample image as reference: Cheers!

Pass By Reference Not Allowed In UI Threading Of Windows Forms In C#

The code below does not allow pass by reference to be used in UI threading particularly method Invoker. private void ShowPassMeta( ref int passedSound) { if (lblPassSoundex.InvokeRequired) { lblPassSoundex.Invoke((MethodInvoker) delegate { ShowPass( ref passedSound); }); } else { lblPassSoundex.Text = (++passedSound).ToString(); } } The solution is to store the method parameter in another variable as shown below: private void ShowPassMeta( ref int passedSound) { var passedSound1 = passedSound; if (lblPassSoundex.InvokeRequired) { lblPassSoundex.Invoke((MethodInvoker) delegate { ShowPassMeta( ref passedSound1); }); } else { lblPassSoundex.Text = (++passedSound1).ToString(); } } Cheers!

Error 1064 Insert Statement Using MySQL Parameters In C#

Good evening! The code above has a database field called desc which is a reserved word in SQL as an order by criteria. dbQuery = String.Format( @"INSERT INTO accom_temp_hotelagencies(hotel_id, agency_id, hotel_webid, desc)VALUES(?HotelId, ?AgencyId, ?HotelWebId, ?Description)" ); The solution is to enclose the field name desc with an acute or back quote. as shown in the code below: dbQuery = String.Format( @"INSERT INTO accom_temp_hotelagencies(hotel_id, agency_id, hotel_webid, `desc`)VALUES(?HotelId, ?AgencyId, ?HotelWebId, ?Description)" ); Cheers!

LINQ Slow Performance In Checking Almost 1 Million Or Large Data (Optimization Problem) In C#

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 s

Debugging jQuery Or 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

ASP.NET MVC C# Razor Syntax Quick Reference

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

WebService Is Undefined Error In ASP.NET 4.0

1. First step is to add reference to the web service using Ajax Script Manager: <asp:ScriptManager ID= "ajaxManager" runat= "server" > <Services> <asp:ServiceReference Path= "~/Services/ProductService.asmx" /> </Services> </asp:ScriptManager> 2. Secondly is to include the namespace in calling the webservice method From ProductService.GetProducts( function (data) { $.each(data, function (index, elem) { $( "<option />" ) .text(elem.ProductName) .val(elem.ProductID) .appendTo( "#products" ); }); } ); To AccessingServerSideDataUsingClientScript.Services.ProductService.GetProducts( function (data) { $.each(data, function (index, elem) { $( "<option />" )

Example Of IsPalindrome Generic Function Using Queue In C#

Hello, Excerpt from .NET 4.0 Generic's Guide , there's an example on testing whether a string is Palindrome using a Stack<T> object. I decided to create a a Queue<T> based method. One additional tip was to reverse the Queue object. See sample function below: public static bool IsPalindromic<T>(IEnumerable<T> inputSequence) where T : IComparable { Queue<T> buffer = new Queue<T>(); foreach (T element in inputSequence) { buffer.Enqueue(element); } buffer = new Queue<T>(buffer.Reverse()); for ( int i = 0; i < inputSequence.Count(); i++) { if (buffer.Dequeue().CompareTo(inputSequence.ElementAt(i)) == 0) { continue ; } else return false ; } return true ; } Source Code: Example Of IsPalindrome Generic Function Using Queue In C# That

Donate