SQL Server 2000 Simplified Chinese Character Data Transformation Example (com,.net)

Source: Internet
Author: User
Tags command line execution
server| Chinese Characters | Simplified reproduction | Data SQL Server 2000 The example of Chinese character data conversion (com,.net)

First verify that the. Net Framework 1.1 is installed on Windows (the server side of the SQL Server, of course)!

Confirm after successful installation:
1. Create a strong-name key file for the class library using Sn-k:
Execute the following command line under the v1.1\bin\ subdirectory in the directory where the Microsoft. Net Framework SDK is installed:
Sn.exe-k c:\snkey.snk

2. Open Notepad (NotePad.exe) to write the following C # program and save 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);
Simplified conversion can also stringconvert parameter control, do not repeat
}
}
}

3. Run cmd under Windows and 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 there are errors, refer to csc.exe/? Help, or MSDN fix!
After confirming the correct execution, this example will generate: C:\Microshaoft.dll file!

4. Execute the following command line again:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regasm.exe C:\microshaoft.dll/tlb:microshaoft.tlb/codebase
Confirm the correct execution, the type library registration is successful, will generate: C:\Microshaoft.tlb file!

5. Write the following T-SQL creation functions and test queries (members of the sysadmin, such as SA, do):

(The CSDN article for T-SQL calls COM components is available for reference)

Create function Udf_stringconvert (@ varchar (8000))
Returns varchar (8000)
As
Begin
--declare @ varchar (8000)
--set @ = ' Ajie speed is very high '
DECLARE @object int
DECLARE @hr int
DECLARE @source varchar (255), @description varchar (255)
DECLARE @Return varchar (8000)
Set @return = '
EXEC @hr = sp_OACreate ' microshaoft.strings ', @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 speed is extremely high ')
Return @return
End

Go

SELECT dbo. Udf_stringconvert (' Ajie speed is extremely high ')



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.