How to retrive a .doc file from DB(SQLSERVER2005) in Windows Application C#

  • 12 years ago
    Hi,
       i had uploaded .doc file in DB , now i want to get .doc file from DB(SQLSERVER2005)....in windows application C# only...

    i tried it like.....

    private void display_btn_Click(object sender, EventArgs e)
            {           
                SqlCommand command = new SqlCommand("select Content from TestTable where FileName = '" + textBox1.Text + "'",cn);
                command.Connection = cn;
                cn.Open();
                byte[] bytes;
                bytes = (byte[])command.ExecuteScalar();             
                MemoryStream ms = new MemoryStream(bytes);
                Bitmap content = new Bitmap(ms);
                textBox2.Text = content.ToString();
                cn.Close();
            }

    i didn't get this....
     i got Exception : ArgumentNullException was                Unhandled
     Buffer cannot be null.
    Parameter name: buffer

    even i enter the file in TextBox1 also i got this exception at  MemoryStream ms = new MemoryStream(bytes);


    Can anyone plzzzzzzz help me in this issue...........plzzzzzzzzzzzzzzzz

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Better train people and risk they leave – than do nothing and risk they stay.” - Anonymous