• C#中使用Oracle


     1:使用存储过程

                string mConn = "Data Source=orcl;User Id=dzzj;Password=dzzj;";  //连接数据库
                conn = new OracleConnection(mConn);
                try
                {
                    conn.Open();
                    cmd = new OracleCommand("sp_file_zh",conn); 
                    cmd.CommandType = CommandType.StoredProcedure;  //调用的是存储过程
                    OracleParameter[] parameters ={
                                       new OracleParameter("msg",OracleType.NVarChar,20),
                                      new OracleParameter("c",OracleType.Int32),
                                       new OracleParameter("ref_cursor",OracleType.Cursor)
                                                    };
                    parameters[0].Direction = ParameterDirection.Output;
                    parameters[1].Direction = ParameterDirection.Output;
                    parameters[2].Direction = ParameterDirection.Output;
                    foreach (OracleParameter parameter in parameters)
                    {
                        cmd.Parameters.Add(parameter);
                    }
                    OracleDataAdapter orda = new OracleDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    orda.Fill(ds);
                    return ds;  //返回结果集
                }
                catch (Exception e)
                {
                    throw e;
                }

    2:使用普通语句

            private string Login(string uName, string pwd)
            {
                string mark = "";
                string sqlstr = "select * from usr where loginName=:lName and pwd=:lPwd";
                OracleConnection orclCon = new OracleConnection(OrclConnection);
                OracleCommand Cmd = new OracleCommand(sqlstr, orclCon);
                Cmd.Parameters.AddWithValue(":lName", uName);
                Cmd.Parameters.AddWithValue(":lPwd", pwd);           
                orclCon.Open();
                OracleDataReader reader = Cmd.ExecuteReader();
                if (reader.Read())
                {
                    HttpContext.Current.Session["UserName"] = uName;
                    mark = "success";
                }
                else
                {
                    mark = "fail";
                }
                return mark;
            }

  • 相关阅读:
    第35条:注解优先于命名模式
    Apache Shiro入门实例
    第34条:用接口模拟可伸缩的枚举
    Lua数组排序
    C++多态性的理解
    爱推软件
    VMProtect使用小计【一】
    android软件开发之webView.addJavascriptInterface循环渐进【二】
    cocos2dx如何添加popScene的场景动画
    Cocos2d-x 3.0 cocostudio骨骼动画的动态换肤
  • 原文地址:https://www.cnblogs.com/jsping/p/2669191.html
Copyright © 2020-2023  润新知