SQL Server 2000 simplified and Complex Conversion of Chinese character data (COM,. Net)
First, make sure that. NET Framework 1.1 is installed on Windows (of course only the SQL Server server!
After successful installation:
1. Use Sn-K to create a strong-name key file for the Class Library:
Run the following command in the V1.1/bin/subdirectory where the Microsoft. NET Framework SDK is installed:
Sn.exe-k c:/snkey. SNK
2.open the notepad (notepad.exe) and write the following C # program and save it as a C:/microshaoft. CS file:
Using system;
Using system. runtime. interopservices;
Using system. reflection;
Using system. runtime. compilerservices;
[Assembly: assemblykeyfile ("snkey. SNK")]
Namespace microshaoft
{
Public interface istrings
{
String stringconvert (string X );
}
[Classinterface (classinterfacetype. autodual)]
Public class strings: istrings
{
Public String stringconvert (string X)
{
Return Microsoft. VisualBasic. Strings. strconv (x, Microsoft. VisualBasic. vbstrconv. traditionalchinese, system. Globalization. cultureinfo. currentculture. lcid );
/// Simple conversion can also be added with stringconvert parameter control.
}
}
}
3. Run CMD in Windows to go to the command line console and execute the following command line:
C:/Windows/Microsoft. net/framework/v1.1.4322/csc.exe/T: Library/out: C:/microshaoft. dll c:/microshaoft. CS/R: C:/Windows/Microsoft. net/framework/v1.1.4322/Microsoft. visualBasic. DLL
If any error occurs, refer to csc.exe /? Help, or msdn correction!
After you confirm the correct execution, this example will generate the: C:/microshaoft. dll file!
4. Execute the following command line:
C:/Windows/Microsoft. NET/framework/v1.1.4322/regasm.exe C:/microshaoft. dll/TLB: microshaoft. TLB/codebase
After you confirm the correct execution, the Type Library registration is successful and the: C:/microshaoft. TLB file will be generated!
5. Write the following T-SQL to create a function and test the query (SysAdmin members such as SA ):
(T-SQL calls COM components csdn articles for reference)
Create Function udf_stringconvert (@ varchar (8000 ))
Returns varchar (8000)
As
Begin
-- Declare @ varchar (8000)
-- Set @ = 'ajie High Speed'
Declare @ object int
Declare @ HR int
Declare @ source varchar (255), @ description varchar (255)
Declare @ return varchar (8000)
Set @ return =''
Exec @ hR = sp_oacreate 'microshaoft. string', @ object out
If @ hR = 0
Begin
Exec @ hR = sp_oamethod @ object, 'stringconvert', @ return out ,@
If @ HR <> 0
Begin
Exec @ hR = sp_oageterrorinfo @ object, @ source out, @ description out
Set @ return = @ object + ''+ @ source +'' + @ description
End
End
Else
Begin
Exec @ hR = sp_oageterrorinfo @ object, @ source out, @ description out
Set @ return = @ object + ''+ @ source +'' + @ description
End
Exec @ hR = sp_oadestroy @ object
-- Select @ return
-- Select DBO. udf_stringconvert ('ajie High Speed ')
Return @ return
End
Go
Select DBO. udf_stringconvert ('ajie High Speed ')