Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3949094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:27:10+00:00 2026-05-20T01:27:10+00:00

I have to persist a .csv in my database, but for a more testable

  • 0

I have to persist a .csv in my database, but for a more testable application I prefer don’t use procedures.
Basically I just generate a file and the next instruction is put this in database.

Someone have some clue about best way to do this in code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:27:11+00:00Added an answer on May 20, 2026 at 1:27 am

    Here is an example to insert blob data in oracle using c# and procedures (you said prefer that means you may).

    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    using System.IO;
    using System.Text;
    
    //Step 1
    // Connect to database
    // Note: Modify User Id, Password, Data Source as per your database setup
    string constr = "User Id=Scott;Password=tiger;Data Source=orcl9i";
    
    OracleConnection con = new OracleConnection(constr);
    con.Open();
    Console.WriteLine("Connected to database!");
    
    // Step 2
    // Note: Modify the Source and Destination location
    // of the image as per your machine settings
    String SourceLoc  = "D:/Images/photo.jpg";
    String DestinationLoc = "D:/Images/TestImage.jpg";
    
    // provide read access to the file
    
    FileStream fs = new FileStream(SourceLoc, FileMode.Open,FileAccess.Read);
    
    // Create a byte array of file stream length
    byte[] ImageData = new byte[fs.Length];
    
    //Read block of bytes from stream into the byte array
    fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));
    
    //Close the File Stream
    fs.Close();
    
    // Step 3
    // Create Anonymous PL/SQL block string
    String block = " BEGIN " +
                   " INSERT INTO testblob (id, photo) VALUES (100, :1); " +
                   " SELECT photo into :2 from testblob WHERE id = 100; " +
                   " END; ";
    
    // Set command to create Anonymous PL/SQL Block
    OracleCommand cmd = new OracleCommand();
    cmd.CommandText = block;
    cmd.Connection = con;
    
    
    // Since executing an anonymous PL/SQL block, setting the command type
    // as Text instead of StoredProcedure
    cmd.CommandType = CommandType.Text;
    
    // Step 4
    // Setting Oracle parameters
    
    // Bind the parameter as OracleDbType.Blob to command for inserting image
    OracleParameter param = cmd.Parameters.Add("blobtodb", OracleDbType.Blob);
    param.Direction = ParameterDirection.Input;
    
    
    // Assign Byte Array to Oracle Parameter
    param.Value = ImageData;
    
    // Bind the parameter as OracleDbType.Blob to command for retrieving the image
    OracleParameter param2 = cmd.Parameters.Add("blobfromdb", OracleDbType.Blob);
    param2.Direction = ParameterDirection.Output;
    
    // Step 5
    // Execute the Anonymous PL/SQL Block
    
    // The anonymous PL/SQL block inserts the image to the
    // database and then retrieves the images as an output parameter
    cmd.ExecuteNonQuery();
    Console.WriteLine("Image file inserted to database from " + SourceLoc);
    
    // Step 6
    // Save the retrieved image to the DestinationLoc in the file system
    
    // Create a byte array
    byte[] byteData = new byte[0];
    
    // fetch the value of Oracle parameter into the byte array
    byteData = (byte[])((OracleBlob)(cmd.Parameters[1].Value)).Value;
    
    // get the length of the byte array
    int ArraySize = new int();
    ArraySize = byteData.GetUpperBound(0);
    
    // Write the Blob data fetched from database to the filesystem at the
    // destination location
    FileStream fs1 = new FileStream(@DestinationLoc,
                                    FileMode.OpenOrCreate, FileAccess.Write);
    fs1.Write(byteData, 0,ArraySize);
    fs1.Close();
    
    Console.WriteLine("Image saved to " + DestinationLoc + " successfully !");
    Console.WriteLine("");
    Console.WriteLine("***********************************************************");
    Console.WriteLine("Before running this application again, execute 'Listing 1' ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a database that persist our metadata and data. Our metadata is produced
I have an application that has many different types of objects that each persist
Hi i have an application developed on XP with Text ODBC drivers. But when
I have enum ClientType{INTERNAL,ADMIN}, i am able to persist enum with hibernate annotations. but
We have created a control that needs to persist data via the ViewState property
I have an IScriptControl that needs to persist data from the user across postbacks.
I have a set of configuration items I need to persist to a human
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.