C#接続oracleインスタンス

2086 ワード

1.C#でoracleを使用するには System.Data.OracleClient.dll
2.例:
 
private string connStr = "data source=WFD;User Id=cas;Password=cas;";
private OracleConnection conn = null;

/// <summary>
        ///     
        /// </summary>
        /// <returns></returns>
        public OracleConnection getConnection()
        {
            try
            {
                if (conn == null) 
                {
                    conn = new OracleConnection(connStr);
                }
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                return conn;
            }
            catch (OracleException e)
            {
                throw e;
            }
        }

/// <summary>
        ///     
        /// </summary>
        public void closeConnection()
        {
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
        }

OracleCommand cmd = new OracleCommand();
                cmd.CommandText = "select t.lockflag from cards t WHERE t.cardno = '" + cardno + "'";
                cmd.Connection = this.getConnection();
                OracleDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    string lockstate = r[0].ToString();
                    if ("".Equals(lockstate) || lockstate.Equals("0"))
                    {
                        lblStateResult.Text = "   ";
                    }
                    else if (lockstate.Equals("1"))
                    {
                        lblStateResult.Text = "   ";
                    }
                }