你的位置:首页 > ASP.net教程

[ASP.net教程]C#实现Oracle数据库插入clob字段类型数据


public static void InsertWithLob(OracleConnection conn)
        {
            if (conn!= null && conn.State == ConnectionState.Open)
            {
                try
                {
                    string sqlText = "insert into tb_nclob(id,name,text) values(1,'test',:text)";
                    using (OracleCommand cmd = new OracleCommand(sqlText, conn))
                    {
                        OracleParameter oracleParameter = new OracleParameter("text", OracleType.Clob);
                        oracleParameter.Value = "this is my test";
                        cmd.Parameters.Add(oracleParameter);
                        int rows = cmd.ExecuteNonQuery();

         cmd.Parameters.Clear();
                        return rows;
                    }
                }
                catch (OracleException ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }