Friday, December 12, 2008

Sun Ray Effect

This is what I have been searching for long....
At last, i found it.


Click here to view the tutorial.

Thursday, November 27, 2008

Key column information is insufficient or incorrect. Too many rows were affected by update.

In MS SQL 2000, in a table with no primary key/index/constraint, whenever there is duplicate record, we cannot delete any of the duplicate record, it will give this error:
"Key column information is insufficient or incorrect. Too many rows were
affected by update."

So how is the trick to remove this duplication?
I was searching and finally found something.

here's what we can do:
1. find out which are the duplicate records
SELECT col1, col2, count(*)
FROM t1
GROUP BY col1, col2
HAVING count(*) > 1

2. delete the duplicate by using this sql
set rowcount 1
delete from t1
where col1=1 and col2=1

it works!

Reference: here

Wednesday, November 26, 2008

Access violation at address 10002593 in module ‘LIBMYSQL.dll’ read at address 00000000.

Yeah I continuously got this error after installing xampp.
Maybe u got this too?
Here's how to solve the problem:
1. Choose Start > All Programs > Startup > WinMySQLadmin
2. Click on the my.ini Setup tab in the WinMySQLadmin window. This can be tricky because the error message windows keep popping up on top the WinMySQLadmin window.
3. In the my.ini Setup tab, there’s a big text box and at the bottom, you’ll see
user=root
password=password
4. Delete the second ‘password’ so that those two lines look like this:
user=root
password=
5. Click the ‘Save Modification’ button in the left area of the window, and confirm that you want to save your changes.
6. The error messages should stop now.

Reference: here

Wednesday, November 19, 2008

Unable to read the project file 'something.vbproj'. The system cannot find the path specified

I have encountered this error and tried to debug it for quite sometime.
It's kinda annoying as I cannot open the web application.

My solution has reference to this vbproj file as etp file.
I have checked that the reference path to this vbproj file is correct in the etp file (http://localhost/something).
I have tried adding the virtual directory 'something' manually on IIS, but yet it didn't work.

How to work around this problem?
There is a file that contains the visual studio settings for the solution. Not sure what it holds. Things like startup project, page.

If the solution is called mysolution.sln then the file is mysolution.suo. It is a hidden file so you will need to turn on the display of hidden files in windows explorer or use dos.

Delete it and all will be fine. VS will create a new one.
Make a backup of the whole directory if it makes you more comfortable.

Reference: here

And I tried that.. and wala... I can open successfully.

Tuesday, November 11, 2008

Autocomplete control with dropdown

Besides extjs, here's what I found to be useful as dropdown.

Featuring auto-complete dropdown, or auto-complete textarea like Gmail's one, also country listing (PHP)

Reference: here

Resources for date picker: here

Download the code here.

Thursday, October 30, 2008

SQL - Drop, Truncate and Delete

Yeah.. basic things but it might be asked on the interview for Application Consultant position at Barclays.

What is the difference between Drop, Truncate and Delete?
Drop is to remove the whole table including the structure.
Truncate is to clean the table, delete all the data within the table.
Delete is to delete a record from the table.

So delete from table and truncate is the same?
The answer is no.

Delete will lock the table, but truncate will not.
That's the main difference!

Friday, October 10, 2008

Inserting Large Amount of Data - Bulk Insert

In order to pass a large amount of data, in VB.NET we can use Bulk Insert, here's the article for more information on the sample too.
Bulk insert sample in vbs file, click here.

If you need to create an XML from the Dataset, then u can click here.

Here's a sample on reading XML format in stored procedure:
DECLARE @idoc int

DECLARE @doc varchar(1000);

Select @doc ='
<ROOT>
<Customer CustomerID="1" ContactName="John 1"/>
<Customer CustomerID="2" ContactName="John 2"/>
<Customer CustomerID="1" ContactName="John 3"/>
<Customer CustomerID="2" ContactName="John 4"/>
</ROOT>'

EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

SELECT *
FROM OPENXML (@idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))

EXEC sp_xml_removedocument @idoc

Please take note that this is not reading from the physical XML file, this can only be used for reading table field with the value of XML formatted text.
More info on feeding XML to Stored Procedure, click here.

This is a sample of reading physical file from the stored procedure, but I have not tested it as I do not have this permission in my office development environment.
EXECUTE permission denied on object 'sp_OACreate', database 'master', owner 'dbo'.
I guess this action requires sysadmin rights.
declare @objFSys int
declare @objFile int
declare @blnEndOfFile int
declare @strLine varchar(4000)

exec sp_OACreate 'Scripting.FileSystemObject', @objFSys out

-- Change the file path to the one that is passed to your stored procedure
exec sp_OAMethod @objFSys, 'OpenTextFile', @objFile out, 'C:\test.txt', 1
exec sp_OAMethod @objFile, 'AtEndOfStream', @blnEndOfFile out
while @blnEndOfFile=0 begin
exec sp_OAMethod @objFile, 'ReadLine', @strLine out
-- Here you got one line from the file
select @strLine
exec sp_OAMethod @objFile, 'AtEndOfStream', @blnEndOfFile out
end
exec sp_OADestroy @objFile
exec sp_OADestroy @objFSys

Thursday, October 9, 2008

Running SQL in bat file

For MS SQL Server 2000, we can use osql.
click here and here for some samples.

For MS SQL Server 2005, we can use sqlcmd.
Click here for more info

For Oracle, we can use sqlplus.

Tuesday, September 30, 2008

Stored Procedure QUOTED_IDENTIFIER and ANSI_NULLS

SET QUOTED_IDENTIFIER (Transact-SQL)

Causes SQL Server to follow the ISO rules regarding quotation mark delimiting identifiers and literal strings. Identifiers delimited by double quotation marks can be either Transact-SQL reserved keywords or can contain characters not generally allowed by the Transact-SQL syntax rules for identifiers.

When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks.

When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers. Literals can be delimited by either single or double quotation marks.

Reference: here

SET ANSI_NULLS

Specifies SQL-92 compliant behavior of the Equals (=) and Not Equal to (<>) comparison operators when used with null values.

When SET ANSI_NULLS is ON, a SELECT statement using WHERE column_name = NULL returns zero rows even if there are null values in column_name. A SELECT statement using WHERE column_name <> NULL returns zero rows even if there are nonnull values in column_name.

When SET ANSI_NULLS is OFF, the Equals (=) and Not Equal To (<>) comparison operators do not follow the SQL-92 standard. A SELECT statement using WHERE column_name = NULL returns the rows with null values in column_name. A SELECT statement using WHERE column_name <> NULL returns the rows with nonnull values in the column. In addition, a SELECT statement using WHERE column_name <> XYZ_value returns all rows that are not XYZ value and that are not NULL.

Reference: here

Wednesday, September 24, 2008

Send Ctrl+Alt+Del to Remote Desktop

In order to change the account password in Windows Server via Remote Desktop, we can use Ctrl+Alt+Del.

How to send this command via Remote Desktop?
Press Ctrl+Alt+END

Tuesday, September 23, 2008

SQL Store Procedure CURSOR

I just learnt stored procedure with cursor pointer.

Here's an example:
BEGIN
DECLARE @MyID AS BIGINT
DECLARE MyIDCursor CURSOR FOR
SELECT ID FROM MyTable
OPEN MyIDCursor

FETCH NEXT FROM MyIDCursor INTO @MyID
WHILE @@FETCH_STATUS=0 -- this is necessary to loop
BEGIN
-- print it out
print '@MyID'
print @MyID
-- to assign to the next value, without this, it will loops forever!
FETCH NEXT FROM MyIDCursor INTO @MyID
END

CLOSE MyIDCursor
DEALLOCATE MyIDCursor
END
Actually this method is not recommended, look here.

Monday, September 22, 2008

MSSQL Multiplication and Division Limitation

There was a case at work, the number is not precise enough for multiplication of data type decimal (38,10).

The result will give up to 6 decimal place precision and the rest 4 decimal place follows it will be truncated, replaced with 0.

Here's the sample in SQL Query Analyzer:

DECLARE @CrossRate as decimal(38,10)
DECLARE @ExchRate1 as decimal(38,10)
DECLARE @ExchRate2 as decimal(38,10)

SET @ExchRate1 = 1.3159643631
SET @ExchRate2 = 1.3663000000

SET @CrossRate = @ExchRate1/@ExchRate2
print '@ExchRate1: '
print @ExchRate1
print '@ExchRate2: '
print @ExchRate2
print '@CrossRate: '
print @CrossRate
And here's the result:
@ExchRate1:
1.3159643631
@ExchRate2:
1.3663000000
@CrossRate:
0.9631590000
However for data type decimal (18,10), multiplication result of the two data types will give the same precision - decimal(18,10).

The CrossRate result of decimal (18,10) is
0.9631591620

I am still not yet known how to solve this, as the requirement that we have is for data type decimal (38,10) instead of decimal (18,10). If you have any idea on how to solve this, please let me know. Thanks.

Some updates
My colleague just said that we can use float.
However there are some things to take note:

Float is Approximate-number data type, which means that not all values in the data type range can be represented exactly.

Decimal/Numeric is Fixed-Precision data type, which means that all the values in the data type reane can be represented exactly with precision and scale.

Converting from Decimal or Numeric to float can cause some loss of precision.

Reference: here

Tuesday, August 19, 2008

Fixing NS_ERROR_XPC_JS_THREW_STRING

In htmls using ExtJs, most of the times I encountered this error in firebug:
"Exception: The request to read the property 
HTMLDivElement.nodeType was denied, when calling method:
[nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e
(NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>"
data: no]"

After searching a long time, here's what i found on how to fix it:
One of them saying it will be fixed by adding autocomplete="off" to all text fields.
I tried this however it doesn't really work!

And after I look at this ExtJs forum thread, I tried adding this trackMouseOver:false on my ExtJs grid.
And so far I did not have that error anymore :)
Yay!

ExtJs messagebox sample

Wednesday, July 16, 2008

Flash Overlay Problem

There is a problem when embedding flash into a web page.
For example if you have dropdown, the dropdown values will be covered by the flash.
Hence you won't be able to view all the images like the picture below.



Here's what we need add

for Flash tag embed
<param name=WMode value=Opaque>

for Javascript
fo.addParam("wmode", "opaque");

and wala.. here's the result...



However, this apparently does not work in Linux.

Reference: here

Wednesday, July 9, 2008

Hide/Show FieldLabel in ExtJs form

This is an overriding function to enable hide/show fieldLabel in ExtJs field form.
The current release of ExtJs 2.1 does not support it.

You can use the function hideItem and showItem in order to show/hide the form field.

Put this function in a javascript file eg. ext-override.js
Then include this file into your html file containing ExtJs form.
Ext.override(Ext.form.Field, {
hideItem :function(){
this.formItem.addClass('x-hide-' + this.hideMode);
},

showItem: function(){
this.formItem.removeClass('x-hide-' + this.hideMode);
},
setFieldLabel: function(text) {
var ct = this.el.findParent('div.x-form-item', 3, true);
var label = ct.first('label.x-form-item-label');
label.update(text);
}
});

Thursday, July 3, 2008

Pre-populate combo values

This sample is to populate combo values in html form using javascript.

For manually insertion of the Option values into the combobox.
<script type="text/javascript"> 
function prepopulate(reportType){
document.form1.report_view.options.length = 0;
if (reportType == "Pie_Chart" || reportType == "Bar_Graph"){
document.form1.report_view.options[0] = new Option("Adobe Reader (.pdf)","pdf");
document.form1.report_view.options[1] = new Option("Open Office (.odt)","odt");
}else{
document.form1.report_view.options[0] = new Option("Adobe Reader (.pdf)","pdf");
document.form1.report_view.options[1] = new Option("Microsoft Excel (.xls)","xls");
document.form1.report_view.options[2] = new Option("Open Office (.odt)","odt");
}
}
</script>

In the html part:
<select name="report_type" id = "report_type" onChange="javascript:prepopulate(this.value)">
<option value="Consolidated_Comments">Consolidated Comments</option>
<option value="Pie_Chart">Consolidated Result - Pie Chart</option>
<option value="Bar_Graph">Consolidated Result - Bar Graph</option>
<option value="Individual_Results_Comments">Individual Results (Comments)</option>
<option value="Individual_Results_FreeText">Individual Results (Free Text)</option>
<option value="List_of_Questions">List of Questions</option>
<option value="Individual_Comment">Individual Result</option>
</select>
<select name="report_view">
</select>

Whenever the report type selected is bar graph or pie chart, it will not display the excel report view, else it will return all three report views.

reference: here

Format source code for blogging

Taken from here. Applicable only for the first 25 lines of codes.
Alternative reference: http://codeformatter.blogspot.sg/


Tab size: 2 4 8
Embed Stylesheet:

Copy the HTML below to your clipboard. Insert the HTML of your blog or wiki.


This is an example of what your text will look like.
    • Tabs are converted to spaces.
    • Quotes and other special characters are converted to HTML.
    • Everything is enclose in HTML's 'pre' and 'code' tags.
    • Style is set:
        • Fixed width font.
        • Shaded box.
        • Dotted line border.


the geek sista

geek Slang.
–noun
1. a peculiar or otherwise dislikable person, esp. one who is perceived to be overly intellectual.
2. a computer expert or enthusiast (a term of pride as self-reference, but often considered offensive when used by outsiders.)
3. a carnival performer who performs sensationally morbid or disgusting acts, as biting off the head of a live chicken.
[Origin: 1915- 20; prob. var. of geck (mainly Scots) fool < D or LG gek]

the geek refers to the second meaning.

this blog will contains anything related to programming languages, new technologies, to simple html, etc..

all for the programming knowledge only..