Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to update dbf from Openrowset?
Message
 
 
To
07/01/2009 09:24:53
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01368838
Message ID:
01371680
Views:
16
>>Cetin,
>>
>>You are a prince!
>>Thank's a lot and a prosperous and happy new year to you and yours.
>>
>>BR
>
>LOL. Thanks for your kindness Peter. Here is the sample I promised (I had a SSN like validation code ready):
>
>
using System;
>using System.Data;
>using System.Data.SqlClient;
>using System.Data.SqlTypes;
>using Microsoft.SqlServer.Server;
>using System.Text;
>
>namespace CBSQLUserDefinedFunctions
>{
>    public partial class Transformer
>    {
>        /// <summary>
>        /// 9: Allow digit only
>        /// A: Allow letter only
>        /// !: Convert to uppercase
>        /// N: Allow Digit or Letter
>        /// U: Allow letter only and convert to uppercase
>        /// W: Allow letter only and convert to lowercase
>        /// X: Allow any character
>        /// Any other character is copied as is for display
>        /// </summary>
>        [Microsoft.SqlServer.Server.SqlFunction
>            (DataAccess = DataAccessKind.None, IsDeterministic = true)]
>        public static SqlString Transform(string value, string mask)
>        {
>            byte[] result = new byte[mask.Length];
>            for (int i = 0, j = 0, k = 0; j < mask.Length; j++, k++)
>            {
>                switch (mask[j])
>                {
>                    case '9':
>                        while (i < value.Length && !Char.IsDigit(value[i])) { i++; }
>                        result[k] = i < value.Length ? (byte)value[i++] : (byte)'\x20';
>                        break;
>                    case 'A':
>                        while (i < value.Length && !Char.IsLetter(value[i])) { i++; }
>                        result[k] = i < value.Length ? (byte)value[i++] : (byte)'\x20';
>                        break;
>                    case 'N':
>                        while (i < value.Length && !Char.IsLetterOrDigit(value[i])) { i++; }
>                        result[k] = i < value.Length ? (byte)value[i++] : (byte)'\x20';
>                        break;
>                    case 'U':
>                        while (i < value.Length && !Char.IsLetter(value[i])) { i++; }
>                        result[k] = i < value.Length ? (byte)Char.ToUpper(value[i++]) : (byte)'\x20';
>                        break;
>                    case 'W':
>                        while (i < value.Length && !Char.IsLetter(value[i])) { i++; }
>                        result[k] = i < value.Length ? (byte)Char.ToLower(value[i++]) : (byte)'\x20';
>                        break;
>                    case '!':
>                        result[k] = i < value.Length ? (byte)Char.ToUpper(value[i++]) : (byte)'\x20'; 
>                        break;
>                    case 'X':
>                        result[k] = i < value.Length ? (byte)value[i++] : (byte)'\x20';
>                        break;
>                    default:
>                        result[k] = (byte)mask[j];
>                        break;
>                }
>            }
>            return ASCIIEncoding.ASCII.GetString(result);
>        }
>    };
>}
And the code needed to register and test this one in SQL server:
>
>
use myDatabase
>go
>CREATE ASSEMBLY [SQLMaskApplier]
>FROM N'c:\myLocation\bin\Release\SQLMaskApplier.dll'
>WITH PERMISSION_SET = SAFE
>go
>CREATE FUNCTION [dbo].[Transform](@value [nvarchar](1000), @mask [nvarchar](1000))
>RETURNS [nvarchar](1000) WITH EXECUTE AS CALLER, RETURNS NULL ON NULL INPUT
>AS 
>EXTERNAL NAME [SQLMaskApplier].[CBSQLUserDefinedFunctions.Transformer].[Transform]
>GO
>select dbo.Transform('123456789','999-99-9999')
>
>
>If you use VS then you do like this:
>New project\VC#\SQL server project (add database reference ... - not mandatory but good for automatic deployment and test)
>Project Name rightclick and in context menu "Add new item" - select appropriate one SP, Aggregate, UDF ...
>
>and write your UDF, SP ... whatever. VS automatically add a testing code and you can test/debug it using break points:)
>Cetin

Interesting, thanks a lot.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform