[英]c# retrive pdf file from database
朋友,我創建了一個應用程序,從中我試圖將pdf文件上傳到數據庫中並從數據庫中檢索。 上傳已成功完成。 但是我無法從數據庫中檢索該pdf文件。 請查看我的代碼,並向我建議解決此問題的方法。
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd1 = new SqlCommand("select Docdata from SaveDoc where DocID='" + TextBox1.Text + "'", con);
con.Open();
byte[] b = null;
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
da = new SqlDataAdapter(cmd1);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
b = ((byte[])dt.Rows[0][0]); // Error has came here
Response.ContentType = "application/pdf";
Response.BinaryWrite(b);
}
並且錯誤是“無法將類型為'System.String'的對象轉換為類型為'System.Byte []'”。
這樣做:
b= Encoding.ASCII.GetBytes(dt.Rows[0][0].ToString());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.