//上传图片………………
if (this.FileUpload1.HasFile)
{
Stream mystream = FileUpload1.PostedFile.InputStream;
int length = FileUpload1.PostedFile.ContentLength; byte[] bytes = new byte[length];
mystream.Read(bytes, 0, length);
mystream.Close();
SqlConnection conn = new SqlConnection(stcon);
conn.Open();
string str = "insert into info (photo) values( ' " + bytes + " ') ";
SqlCommand comm = new SqlCommand(str, conn);
comm.ExecuteNonQuery();
conn.Close();
Response.Write("<script language=javascript>alert('上传成功!')</script>");
}
//显示图片………………
try
{
//string imgtype = FileUpload1.PostedFile.ContentType;
SqlConnection conn = new SqlConnection(stcon);
string sql = "select imgtype,photo from info where IDCard='" + Session["id"].ToString() + "'";
SqlCommand command = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{ //Response.ContentType = dr["imgtype"].ToString();
Response.BinaryWrite((byte[])dr["photo"]);
}
else
{ Response.Write("没有从数据库中读取图片 ");
}
conn.Close();
}
catch (Exception x)
{ }
if (this.FileUpload1.HasFile)
{
Stream mystream = FileUpload1.PostedFile.InputStream;
int length = FileUpload1.PostedFile.ContentLength; byte[] bytes = new byte[length];
mystream.Read(bytes, 0, length);
mystream.Close();
SqlConnection conn = new SqlConnection(stcon);
conn.Open();
string str = "insert into info (photo) values( ' " + bytes + " ') ";
SqlCommand comm = new SqlCommand(str, conn);
comm.ExecuteNonQuery();
conn.Close();
Response.Write("<script language=javascript>alert('上传成功!')</script>");
}
//显示图片………………
try
{
//string imgtype = FileUpload1.PostedFile.ContentType;
SqlConnection conn = new SqlConnection(stcon);
string sql = "select imgtype,photo from info where IDCard='" + Session["id"].ToString() + "'";
SqlCommand command = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{ //Response.ContentType = dr["imgtype"].ToString();
Response.BinaryWrite((byte[])dr["photo"]);
}
else
{ Response.Write("没有从数据库中读取图片 ");
}
conn.Close();
}
catch (Exception x)
{ }
解决方案 »
- 数据库设计
- 请教一个排名的sql语句
- sql语句如何在查询结果最后加一行合计
- 求一个SQL语句
- 如何查找数据库的最后几条记录并按原顺序显示出来,不能用order by id desc
- sqlserver中抛出错误的问题, RaiseError(..) 请教!
- 从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界。
- windows身份认证怎么改成SQL的身份认证?
- 大家快帮忙~!!hurry up to help me~~!关于数据库倒入倒出的~~~?
- sql server很简单的初始赋值的问题
- SQL UPDATA语句问题
- SQL Server 2000 表中如何建立只含年月日的日期型列?或实在不能,如何强制时分秒为0也能将就。
System.Byte[] 也是用来读取对应的流文件.
http://dotnet.aspx.cc/article/j9ubrver-l3vb-49m3-gou1-z6c2pvr6fz3k/read.aspx