| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2237 人关注过本帖
标题:vs2005连接oracle
只看楼主 加入收藏
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
 问题点数:0 回复次数:2 
vs2005连接oracle
小弟初学,有哪位能提供些基本的vs2005(C#)连接oracle 9i的源代码吗?谢过啦!
我只知道一个oracleconnection,可是怎么用完全不知道。。。
搜索更多相关主题的帖子: oracle 源代码 初学 
2008-01-28 20:46
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 
没人顶~~~自己搞定了,自己顶,给同样初学的参考下!

class oraDataConnection
    {
        string serveraddress = "carmng";
        string userid = "carmng";

        public OracleConnection getcon(string server,string user)       //返回一个oracle连接
        {
            if (server == "")
                server = serveraddress;
            if (user == "")
                user = userid;

            string constr = "data source="+server+";user="+user+";password=cztesthp380";
            OracleConnection conora = new OracleConnection(constr);

            return conora;
        }

        public DataTable getdatatable(string server,string user,string cmdstr)     //返回一个指定查询的表
        {
            string constr = "data source=" + server + ";user=" + user + ";password=cztesthp380";
            OracleConnection oracon = new OracleConnection(constr);
            oracon.Open();
            DataTable dt = new DataTable();
            OracleDataAdapter ada = new OracleDataAdapter(cmdstr, oracon);
            ada.Fill(dt);
            oracon.Close();

            return dt;
        }

        public DataTable getdatatable(OracleConnection oracon, string cmdstr)     //返回一个指定查询的表
        {
            oracon.Open();
            DataTable dt = new DataTable();
            OracleDataAdapter ada = new OracleDataAdapter(cmdstr, oracon);
            ada.Fill(dt);
            oracon.Close();

            return dt;
        }

        public string insertitem(string server, string user, string cmdstr)        //增加操作
        {
            if (cmdstr.Substring(0, 12) != "insert into ")
            {
                return "非insert语句";
            }

            string constr = "data source=" + server + ";user=" + user + ";password=cztesthp380";
            OracleConnection oracon = new OracleConnection(constr);
            oracon.Open();
            OracleCommand cmd = new OracleCommand(cmdstr, oracon);
            cmd.ExecuteNonQuery();
            oracon.Close();

            return "1";
        }

        public string updateitem(string server, string user, string cmdstr)          //更新操作
        {
            if (cmdstr.Substring(0, 7) != "update ")
            {
                return "非update语句";
            }

            string constr = "data source=" + server + ";user=" + user + ";password=cztesthp380";
            OracleConnection oracon = new OracleConnection(constr);
            oracon.Open();
            OracleCommand cmd = new OracleCommand(cmdstr, oracon);
            cmd.ExecuteNonQuery();
            oracon.Close();

            return "1";
        }

        public string deleteitem(string server, string user, string cmdstr)            //删除操作
        {
            if (cmdstr.Substring(0, 12) != "delete from ")
            {
                return "非delete语句";
            }

            string constr = "data source=" + server + ";user=" + user + ";password=cztesthp380";
            OracleConnection oracon = new OracleConnection(constr);
            oracon.Open();
            OracleCommand cmd = new OracleCommand(cmdstr, oracon);
            cmd.ExecuteNonQuery();
            oracon.Close();

            return "1";
        }
    }

努力成为菜鸟!
2008-02-14 16:48
nietao1985
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-8-27
收藏
得分:0 
看不大懂呢……用vs2005的MFC类库,怎么实现ORACLE的调用啊?谢谢啦……
2008-08-27 08:09
快速回复:vs2005连接oracle
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017359 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved