i have access file by name song.mdb which has field by name file
where i am storing mp3 file in binary format .
when i tried to read the field into
ret byte array i am able to read only first 25 bytes .

Why am i not getting the full array which is 1024 bytes long

byte[] ret = new byte[2000];
            mycon.Open();
OleDbCommand cmd = new OleDbCommand("select file from song", mycon);
            System.Data.OleDb.OleDbDataReader dr;
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                ret = (byte[])dr.GetValue(0);
            }

Recommended Answers

All 5 Replies

Upload the access database you are working with.

Upload the access database you are working with.

unable to upload its saying not support file

ZIP it and upload the zip.

ZIP it and upload the zip.

private void button1_Click_1(object sender, EventArgs e)
        {
            String strFileName;
            String str;

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = "C:";
            dialog.Title = "Select a text file";
            if (dialog.ShowDialog() == DialogResult.OK)
                strFileName = dialog.FileName;

            //if strFileName == " ")
            //    return; //user didn't select a file to opena

            //insertsql = "insert into songs(ID,file) values(1,data)";
            str = dialog.FileName;

            FileStream fs = new FileStream(str, FileMode.Open);
            //int Size = 1024;
            byte[] data = new byte[100000];
            int b = fs.Read(data, 0, 100000);
            while (b != 0)
            {
                b = fs.Read(data, 0, 100000);
                
            }
            mycon.Open();
            
            OleDbCommand cmd = new OleDbCommand("INSERT INTO song VALUES('1', '" + data + "')", mycon);
            cmd.ExecuteNonQuery();
            mycon.Close();
            fs.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
        //    byte[] ret = new byte[2000];
        //    mycon.Open();

        //    //OleDbCommand cmd = new OleDbCommand("select file from song", mycon);
        //    //System.Data.OleDb.OleDbDataReader dr;
        //    //dr = cmd.ExecuteReader();
        //    //if (dr.Read())
        //    //{
        //    //    ret = (byte[])dr.GetValue(0);
        //    //}

        //    BinaryReader br = new BinaryReader();
        //    br.Read(

        //    DataSet ds = new DataSet();
        //    OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from song", mycon);
        //    adapter.Fill(ds);


        //    //// close the connection
        //    //mycon.Close();
        //   //ret = (byte[])ds.Tables[0].Rows[0];
        //    ret = (byte[])dr.GetValue(0);
        //    //ret = ds.Tables[0].Rows[0];



        }

hi i have added the whole code in button1_click i am uploading it into ms access database , but still the whole song is not getting stored there and even the half stored song i am unable to retrieve it .

ZIP it and upload the zip.

hi i will tell what exactly is my requirement .
I want to store a mp3 song into ms access database in encrypted format .
Firstly if it gets stored in normal format also its ok .

Later i have to retrieve it and play it .

Now u please correct the code as it has few problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.