Hello,
Is this how to convert pdf file to image when selecting the files from database to display on page load?
private void DisplayDocument()
{
int id = Convert.ToInt32(Request.QueryString["Id"]);
SqlConnection con = new SqlConnection("myConString");
con.Open();
if (Request.QueryString["Id"] != null)
{
string sql = "SELECT * FROM Table WHERE Id = @Id";
SqlParameter[] parameters = new[] {
new SqlParameter("@Id", id)
};
// Bind Image3 for Card Image
DataTable dt = SelectFromDatabase(sql, parameters);
if (dt.Rows.Count > 0)
{
Image3.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String((byte[])dt.Rows[0]["image"]);
Image3.AlternateText = "The document has been found";
}
else
{
Image3.ImageUrl = "#";
Image3.AlternateText = "The document does not exist in DataBase";
}
}
}
public static DataTable SelectFromDatabase(string sql, SqlParameter[] parameters)
{
using (SqlConnection con = new SqlConnection("Data Source=N1NWPLSK12SQL-v02.shr.prod.ams1.secureserver.net;Initial Catalog=Quirver_DB;Persist Security Info=True;User ID=quirverT;Password=#ETEkamba@33"))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (parameters != null)
{
cmd.Parameters.AddRange(parameters);
}
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}