私は画像のバイトを返すSQLサーバーデータベースを持っています。私がテーブルアダプターウィザードを使用して、それを私のストアードプロシージャーとプレビューデータに設定すると、それはイメージを元に戻します。プレビューデータ内の画像に自動的に変換されます。私はそれを文字や文字列としては見ません。asp.netのSQL Serverデータベースからイメージを表示する最適な方法は何ですか?
gridviewとobjectdatasourceを使用してasp.net Webページに表示するにはどうすればよいですか?
イメージフィールドが、バイト変換を行う別のページのURLを指し示すことができる場所を検索して調べましたが、それが最も良いかどうかはわかりません。私は、一時ファイルを作成する別の方法を見つけました。
これを行う最善の方法を試してみます。
編集 - 私は一時ファイルを使用しようとしていません。グリッドビューを使用できない場合、通常の画像フィールドはOKです。
asp.net 2.0、c#。
ありがとうございました。呼び出しページの
protected void Page_Load(object sender, EventArgs e)
{
string id = Request["id"];
string connstr = "DSN=myserver";
OdbcConnection conn = new OdbcConnection(connstr);
OdbcCommand cmd = new OdbcCommand("{call mySP (?)}", conn);
cmd.CommandType = CommandType.StoredProcedure;
// Add the input parameter and set its properties.
OdbcParameter parameter = new OdbcParameter();
parameter.ParameterName = "@MyParam";
parameter.OdbcType = OdbcType.VarChar;
parameter.Direction = ParameterDirection.Input;
parameter.Value = id;
// Add the parameter to the Parameters collection.
cmd.Parameters.Add(parameter);
conn.Open();
OdbcDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
byte[] buffer = (byte[])dr[0];
Response.ContentType = "image/jpg";
Response.BinaryWrite(buffer);
Response.Flush();
}
}
と、この:
編集になってしまった
<asp:Image ID="Image1" ImageAlign="Middle" ImageUrl="show.aspx?id=123" Runat="server" />
+1私はすべてashxハンドラールートです。 – bendewey
私はこれらの方法を使わないことを望んでいました。でもありがとう。 – johnny
別の賛成投票 –