如何在ASP.NET中把图存入数据库,然后再在ASPX页面中显示!!(急,请高手指教)

来源:百度知道 编辑:UC知道 时间:2024/06/11 15:16:42
要一个简单..完整..明了的..谢谢了...

//写入数据库
SqlCommand com = new SqlCommand("插入的sql");
com.Connection = new SqlConnection("连接字符串");
com.Parameters.Add("image类型字段",SqlDbType.Image,"文件长度").Value = ReadFile("文件路径");
com.Connection.Open();
com.ExecuteNonQuery();
com.Connection.Close();

//显示
SqlCommand com = new SqlCommand("查询的sql");
com.Connection = new SqlConnection("连接字符串");
DataSet ds = new DataSet();
SqlDataAdapter da = null;
com.Connection.Open();
da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
com.Connection.Close();
Getfile(ds);
<img src="文件路径">
#region 产生文件

private void Getfile(DataSet ds)
{
FileStream fs;
int len;
int i = 0;
byte[] buf;

if(ds!=null)
{
if(!Convert.IsDBNull(ds.Tables[0].Rows[0]["字段名"]))