标题:oracle的数据库连接
只看楼主
adrian0
Rank: 2
等 级:论坛游民
帖 子:78
专家分:70
注 册:2010-1-28
结帖率:100%
已结贴  问题点数:20 回复次数:1 
oracle的数据库连接
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";
        }
    }
搜索更多相关主题的帖子: 数据库 oracle 
2010-02-02 17:18
soky
Rank: 4
等 级:业余侠客
帖 子:126
专家分:228
注 册:2009-7-13
得分:20 
感谢分享
2010-02-04 05:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-297103-1-1.html




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

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