我已经将PDF文件作为二进制数据文件上传到我的SQL Server数据库中。我想检索此文件并在我的表单上使用Adobe Reader打开它。
请帮忙;我正在使用Visual Studio 2015
提前致谢。
我尝试了这个,但仍然没有结果:
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();
}
和此:
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();
}