'Display a PDF file from SQL Server database using C#

I already uploaded PDF files into my SQL Server database as binary data file. I want to retrieve this file and open it with Adobe Reader on my form.

Please help; I am using Visual Studio 2015

Thanks in advance.

I try this but still no results:

 private void button1_Click(object sender, EventArgs e)
 {
     DEFAUTHEQUE def = new DEFAUTHEQUE();

     SqlCommand cmd = new SqlCommand("select * from articles where matricule_article='" + textBox3.Text + "'", con);

     SqlDataReader read = cmd.ExecuteReader();

     while (read.Read())
     {
         if (!read.IsDBNull(read.GetOrdinal("fiche_cond")))
         {
             byte[] pa = (byte[])read["fiche_cond"];
             File.WriteAllBytes("file.pdf", pa);

             string path = @"C:\Users\faten\Documents\Visual Studio 2015\Projects\application_microtechnic-270418-14h43\application_microtechnic-270418-14h43\Resources\file.pdf";
             def.axAcroPDF1.src = path;
         }
      }

      read.Close();
      def.Show();
  }

and this:

private void button1_Click(object sender, EventArgs e)
{
    DEFAUTHEQUE def = new DEFAUTHEQUE();

    DataSet ds = new DataSet();
    string path = @"C: \Users\faten\Documents\Visual Studio 2015\Projects\file.pdf";

    using (SqlDataAdapter cmd = new SqlDataAdapter("select * from articles where matricule_article='eee'", con))
    {
        cmd.Fill(ds);
        string s = textBox3.Text;
        int c = ds.Tables[0].Rows.Count;
        byte[] bytes = (byte[])ds.Tables[0].Rows[0]["fiche_cond"];

        MemoryStream memStream = new MemoryStream(bytes);
        File.WriteAllBytes(path, bytes);

        def.axAcroPDF1.LoadFile(path);
    }

    def.show();
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source