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.