加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

汉字在VB和oracle 以及C#和oracle之间乱码问题

发布时间:2020-12-17 07:34:35 所属栏目:百科 来源:网络整理
导读:?? oracle 数据库用字符集AL32UTF8,VB程序通过ADODB连接数据库。存储的汉字在数据库里面是乱码。但是通 过VB程序解读出来的汉字确是正确的。换成C#程序,连接oracle数据库,无论是用ADO.NET还是,oracleclient。 读取的汉字都是乱码。后来在网上看到C#也可
??

oracle 数据库用字符集AL32UTF8,VB程序通过ADODB连接数据库。存储的汉字在数据库里面是乱码。但是通

过VB程序解读出来的汉字确是正确的。换成C#程序,连接oracle数据库,无论是用ADO.NET还是,oracleclient。

读取的汉字都是乱码。后来在网上看到C#也可以用ADODB存取数据库。在C#程序中改为ADODB访问oracle。这

下汉字终于可以正常显示了。后来发现ADO.NET和oracleclient是微软的,ADODB是PHP里面常用的。不是同一
家公司。要用ADODB只需要在工程的引用中添加C:Program FilesCommon FilesSystemadomsado15.dll,

System.Reflection.Missing vtmissing = System.Reflection.Missing.Value;
            ADODB.Recordset Rs = new ADODB.Recordset();
            string sSql = " SELECT ROWNUM,a.user_id as user_id,b.name as name,a.lot_no as lot_no,a.update_time as update_time FROM FCB_UNLOCK_LOG a,User_List b "
                          +" WHERE a.user_id=b.user_id(+)  "
                          +" ORDER BY a.update_time DESC ";
            string conn = @"Driver={Microsoft ODBC for Oracle};Server=test;UID=test;PWD=test;";
            Rs.Open(sSql,conn,ADODB.CursorTypeEnum.adOpenKeyset,ADODB.LockTypeEnum.adLockOptimistic,(int)ADODB.CommandTypeEnum.adCmdText);
            DataTable dt = new DataTable();
            dt.Columns.Add("SN",System.Type.GetType("System.String"));
            dt.Columns.Add("Employee ID",System.Type.GetType("System.String"));
            dt.Columns.Add("Name",System.Type.GetType("System.String"));
            dt.Columns.Add("     Lot#     ",System.Type.GetType("System.String"));
            dt.Columns.Add("    Datime     Unlock    ",System.Type.GetType("System.String"));
            if (!Rs.EOF && !Rs.BOF)
            {
                Rs.MoveFirst();
                while (!Rs.EOF)
                {
                    DataRow row=dt.NewRow();
                    row[0] = Rs.Fields["ROWNUM"].Value;
                    row[1] = Rs.Fields["user_id"].Value;
                    row[2] = Rs.Fields["name"].Value;
                    row[3] = Rs.Fields["lot_no"].Value;
                    row[4] = Rs.Fields["update_time"].Value;
                    Rs.MoveNext();
                    dt.Rows.Add(row);
                }
            }
            Rs.Close();

同时VB生成的DLL,在C#程序中也可以调用。比如生成的vb DLL工程为Project1,里面有函数test().在C#

中添加引用Project1.DLL

Project1.Class1 vbpassword = new Project1.Class1(); vbpassword.test();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读