ebattulga
ebattulga

Reputation: 10981

How do I search HTML formatted text in SQL?

I'm using Microsoft SQL Server 2000 and I have 3 problems.

  1. My web site saves some HTML formatted text into an ntext field. How do I search this field?
  2. I asked a question here before (how to search from all field in sql), but I need to know which field the search result was found in.
  3. I save some fields that use .NET encryption. How can I search this field? It is possible?

Upvotes: 0

Views: 273

Answers (2)

ebattulga
ebattulga

Reputation: 10981

My encryption is here>>

public string Encrypt(string strText, string strEncKey)
    {
        Byte[] byKey;
        Byte[] IV ={ 0x12, 0x34, 0x54, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        byKey = Encoding.UTF8.GetBytes(strEncKey);
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
        MemoryStream ms = new MemoryStream();
        CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
        cs.Write(inputByteArray, 0, inputByteArray.Length);
        cs.FlushFinalBlock();
        return Convert.ToBase64String(ms.ToArray());
    }
    public string Decrypt(string strText, string strEncKey)
    {
        Byte[] byKey;
        Byte[] IV ={ 0x12, 0x34, 0x54, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        Byte[] inputByteArray;

        byKey = Encoding.UTF8.GetBytes(strEncKey.Substring(0, 8));
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        inputByteArray = Convert.FromBase64String(strText);

        MemoryStream ms = new MemoryStream();
        CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
        cs.Write(inputByteArray, 0, inputByteArray.Length);
        cs.FlushFinalBlock();

        return System.Text.Encoding.UTF8.GetString(ms.ToArray());
    }

Using >>

Encrypt(value, "&%#@?,:*");
Decrypt(value, "&%#@?,:*");

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300529

You can use LIKE or PATINDEX() to search for a wildcard expression within a ntext (or nvarchar(max)) column.

Upvotes: 1

Related Questions