我正在尝试在oracle数据库中存储Unicode数据(印地语语言字符)而不是存储在以这种格式存储的印地文字符中????
我正在使用Oracle 10g,我已将数据库字符集设置为AL32UTF8 我的表脚本
create table UTF
(
ENGLISH_NAME VARCHAR2(10),
HINDI_NAME NVARCHAR2(10)
)
我正在使用visual studio 13
我正在使用谷歌API进行翻译
<script>
function OnLoad() {
var options = {
sourceLanguage:
google.elements.transliteration.LanguageCode.ENGLISH,
destinationLanguage:
[google.elements.transliteration.LanguageCode.HINDI],
shortcutKey: 'ctrl+g',
transliterationEnabled: true
};
var control = new google.elements.transliteration.TransliterationControl(options);
control.makeTransliteratable(["txtHindi"]);
var keyVal = 32; // Space key
$("#txtEnglish").on('keydown', function (event) {
if (event.keyCode === 32) {
var engText = $("#txtEnglish").val() + " ";
var engTextArray = engText.split(" ");
$("#txtHindi").val($("#txtHindi").val() + engTextArray[engTextArray.length - 2]);
document.getElementById("txtHindi").focus();
$("#txtHindi").trigger({
type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
});
}
});
$("#txtHindi").bind("keyup", function (event) {
setTimeout(function () { $("#txtEnglish").val($("#txtEnglish").val() + " "); document.getElementById("txtEnglish").focus() }, 0);
});
} //end onLoad function
google.setOnLoadCallback(OnLoad);
C#.Net插入代码
public int insert(person d)
{
String Query;
string ConnStr = new ConnectionClass().ConnStr();
using (OleDbConnection conn = new OleDbConnection(ConnStr))
{
Query = "insert into UTF(ENGLISH_NAME, HINDI_NAME) VALUES('" + d.ENGLISH_NAME + "','" + d.HINDI_NAME + "')";
OleDbCommand cmd = new OleDbCommand(Query, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
return 1;
}
答案 0 :(得分:0)
将您的Query
更改为此(请勿更改,此部分仅供参考):
Query = "insert into UTF(ENGLISH_NAME, HINDI_NAME) VALUES('" + d.ENGLISH_NAME + "',N'" + d.HINDI_NAME + "')";
您需要使用字母N前缀Unicode字符串常量。如果没有N前缀,则将字符串转换为数据库的默认代码页。此默认代码页可能无法识别某些字符。
(实际部分你需要做什么)
使用参数化SQL查询。 How and Why to Use Parameterized Queries
Query = "insert into UTF(ENGLISH_NAME, HINDI_NAME) VALUES( @ENGLISH_NAME, @HINDI_NAME)";
cmd.Parameters.Add(new OleDbParameter("@ENGLISH_NAME",d.ENGLISH_NAME));
cmd.Parameters.Add(new OleDbParameter("@HINDI_NAME",d.HINDI_NAME));