朋友, 我已經創建了一個應用程序,從那裏我試圖將pdf文件上傳到數據庫並從數據庫中取回。已上傳已成功完成。但我無法從數據庫中檢索該pdf文件。請看我的代碼,並建議我從這個問題出來的方式。c#從數據庫中取回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 []'」。
只是儘量把它作爲字符串返回,並期待在字符串的內容進一步調查 –