简体   繁体   English

如何在Advantage SQL数据库中插入特殊字符?

[英]How can I insert special characters into Advantage SQL database?

I'm trying to insert characters like µ as varchar but it doesn't work, I get error message which says 我试图插入像µ作为varchar的字符,但它不起作用,我收到错误消息说

cannot convert Unicode characters to Codepage characters 无法将Unicode字符转换为Codepage字符

because it's medical document, I'm not allowed to change any data. 因为它是医疗文件,我不允许更改任何数据。 The program is written in vb.net, it inserts csv data into Advantage SQL so I was trying this function 该程序是用vb.net编写的,它将csv数据插入Advantage SQL,所以我尝试了这个功能

 Public Shared Function Convert(ByVal input As String) As String
      Dim OriginalCodierung As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
        Dim iso8859 As System.Text.Encoding = System.Text.Encoding.GetEncoding("iso-8859-1")
        Dim enc As System.Text.Encoding = System.Text.Encoding.Default

       Dim OriginalBytes As Byte() = OriginalCodierung.GetBytes(input)
        Dim result As Byte() = System.Text.Encoding.Convert(OriginalCodierung, iso8859, OriginalBytes)
        Dim s As String = enc.GetString(result)
        Return s

    End Function

which encodes utf8 in iso8859 but it didn't really help. 在iso8859中编码utf8但它没有真正帮助。

How can I insert the data with those characters without changing the data? 如何在不更改数据的情况下插入包含这些字符的数据?

i don't know if this will answer your question: 我不知道这是否会回答你的问题:

Use parametrized queries: 使用参数化查询:

using (SqlCommand com = new SqlCommand("INSERT INTO your_Table (column) " +
                                       "VALUES (@INPUTVALUE)", con))
    {
    com.Parameters.AddWithValue("@INPUTVALUE", @"""%$#@?,.;");
    com.ExecuteNonQuery();
    }

To escape special characters in a LIKE expression you prefix them with an escape character. 要转义LIKE表达式中的特殊字符,请在其前面加上转义字符。 You get to choose which escape char to use with the ESCAPE keyword. 您可以选择使用ESCAPE关键字的转义字符串。 (as MSDN References) (作为MSDN参考)

For example this escapes the % symbol, using \\ as the escape char: 例如,这会转义%符号,使用\\作为转义字符:

select * from your_table where yourcolumnfield like '%15\\% off%' ESCAPE '\\' 从your_table中选择*,其中你的列字段如'%15 \\%off%'ESCAPE'\\'

If you don't know what characters will be in your string, and you don't want to treat them as wildcards, you can prefix all wildcard characters with an escape char, eg: 如果您不知道字符串中将包含哪些字符,并且您不希望将它们视为通配符,则可以使用转义字符为所有通配符添加前缀,例如:

set @msearchString = replace(
                replace(
                replace(
                replace(@myString,'\','\\'),
                        '%','\%'),
                        '_','\_'),
                        '[','\[') 

(Note that you have to escape your escape char too). (注意你也必须逃避你的转义字符)。 Then you can use something like this: 然后你可以使用这样的东西:

select * from table where yourcolumnfield like '%' + @msearchString + '%' ESCAPE '\'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM