日期:2014-05-17  浏览次数:20904 次

C#实现oracle数据的查询和删除
C# code

public static void doInsertData()
        {
          
            string conStr = "provider='OraOleDb.Oracle';Data Source=" +
            "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))" +
            "(CONNECT_DATA =(SERVICE_NAME = test)));User Id=test;Password=test;";

            string sqlInsertStr = "insert into SYM_SOFTWARE_COLLECTION" +
             "(USERNAME,IP,MAC,YONGYOUSTATUS,YONGYOUEDITION,JINDIESTATUS,JINDIEEDITION,GUANJIAPOSTATUS,GUANJIAPOEDITION,RECORDTIME)" +
                "values('" + username + "','" + ip + "','" + mac + "','" + yySta + "','" + yyEdition + "','" + jdSta + "','"
                    + jdEdition + "','" + gjpSta + "','" + gjpEdition + "', sysdate )";

            String sqlQueryStr = "select * from SYM_SOFTWARE_COLLECTION  where USERNAME='test3';";
            String sqlDeleteStr = "delete from SYM_SOFTWARE_COLLECTION  where USERNAME='test2';";

            OleDbConnection sqlCon = new OleDbConnection(conStr);
            try
            {
                sqlCon.Open();
                //执行插入没问题,执行查询和删除时都有报错了
                //OleDbCommand cmd = new OleDbCommand(sqlInsertStr, sqlCon);

                //OleDbCommand cmd = new OleDbCommand(sqlDeleteStr, sqlCon);

                OleDbCommand cmd = new OleDbCommand(sqlQueryStr, sqlCon);
                
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                sqlCon.Close();
            }
        }




执行查询和删除时都报错了:ORA-00911: invalid character
刚接触oracle
有点急,求有经验的高手帮忙解答一下,谢谢。。。。

------解决方案--------------------
String sqlQueryStr = "select * from SYM_SOFTWARE_COLLECTION where USERNAME='test3';";
String sqlDeleteStr = "delete from SYM_SOFTWARE_COLLECTION where USERNAME='test2';";
双引号里面还有分号。。