The secret to retrieve random rows from database is really simple. Here are some example SQL statements that do not require additional application logic.SQL Server:SELECT TOP 1 *FROM UsersORDER BY NEWID()MySQL:SELECT * FROM UsersORDER BY RAND()LIMIT 1;Oracle:SELECT * FROM(SELECT * FROM UsersORDER BY dbms_random.value )WHERE rownum = 1PostgreSQL:SELECT * FROM UsersORDER BY RANDOM()LIMIT 1Access:SELECT TOP 1 *FROM UsersORDER BY Rnd(UserID)Chee...
Tuesday, December 29, 2009
Generate random rows with SQL
Author: xiaoyu
| Posted at: 3:59 PM |
Filed Under:
ms access,
my sql,
oracle,
sql server
Friday, October 9, 2009
InvalidOperationException: Cross-thread operation not valid: Control ‘Form1’ accessed from a thread other than the thread it was created on.
Author: xiaoyu
| Posted at: 10:40 AM |
Filed Under:
.NET
When I first time met with this error, it was caused by an update of a windows form control from a separate thread.Here is the workaround.// delegation to cross the thread boundaryprivate delegate void AddComboBoxItemDelegate(object item);private void AddComboBoxItem(object item){ if (this.comboBox1.InvokeRequired) { // Invoke delegate so that the main UI thread is able to update the controls in the formthis.comboBox1.Invoke(new AddComboBoxItemDelegate(this.AddComboBoxItem), item); } else...
Wednesday, September 16, 2009
Shrinking Transaction Log File in SQL SERVER
Author: xiaoyu
| Posted at: 12:10 PM |
Filed Under:
sql server
Sometimes it is necessary to shrink a transaction log in a database manually if the log file grows unexpectedly in order to save some disk space.Here are the steps use to truncate transaction log in a database:BACKUP LOG <databasename> TO DISK = '<backupfile>'DBCC SHRINKFILE (<filename>, <targetsize>) WITH NO_INFOMSGSe.g.:BACKUP LOG NORTHWND TO DISK = 'C:\NorthwindLog.bak'DBCC SHRINKFILE (Northwind_log, 100) WITH NO_INFOMSGSTo check your logical file name of your log file, you can run the query as below...
Tuesday, August 25, 2009
CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Author: xiaoyu
| Posted at: 3:29 PM |
Filed Under:
LINQ
Add the line below into web.config:<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>Reference: http://forums.asp.net/t/1264863.a...
Thursday, June 11, 2009
System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase
Author: xiaoyu
| Posted at: 10:23 AM |
I came across with this error yesterday and just had to share it.CAUSE: You have installed Internet Information Services (IIS) after the installation of .NET Framework 2.0RESOLUTION: Repair your .NET Framework 2.0 by running the following command line to reset the IIS registry settings for aspnet user.C:\WINDWOS\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis...
Thursday, February 12, 2009
How to Register DLLs in C#
Author: xiaoyu
| Posted at: 4:31 PM |
The Regsvr32 tool is used to register or un-register DLL or OCX files.Usage:Regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dll_name/u – un-register server/s – to run silently without display any message boxesdll_name – indicates the path and file name of the DLL to register. More than one DLL is allowed in this command.Example:regsvr32 C:\example.ocxregsvr32 /u C:\example.ocxSometimes we need to register DLLs programmatically, the codes below will show you how to invoke the regsvr32.exe and register a dll file in C#.using System.Diagnostics;…public...
Friday, January 9, 2009
Error Message “No more new fonts may be applied in this workbook.” In Excel
Author: xiaoyu
| Posted at: 2:45 PM |
Filed Under:
excel
I am currently working on a project, which I need to export an excel file with more than 100 charts need to be included. And guess what? Yeah…Microsoft Excel throws me this error when I tried to export data into the excel file:No more new fonts may be applied in this workbook.According to Microsoft Help and Support, this problem is being caused because of the enabled Auto Scale setting in my charts and textboxes (I am also adding textboxes in my excel file).This problem occurs because of the Auto scale setting. When you add...
Subscribe to:
Posts (Atom)