62,266
社区成员
发帖
与我相关
我的任务
分享
public void ReadImage(string userName)
{
SqlConnection conn = new SqlConnection(Class.Common.getDBConnStr());
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select photo from tb where UserName='"+userName+"' and photo is not null";
conn.Open();
SqlDataReader sr = cmd.ExecuteReader();
string cStr = "photo" + userName;
if(sr.Read())
{
//bool kk = sr.HasRows;
Cache[cStr] = (byte[])sr["photo"];
Response.BinaryWrite((byte[])sr["photo"]);
}
else
{
byte[] l = {00000000};
Cache[cStr] = (byte[])l;
}
conn.Close();
conn.Dispose();
sr.Close();
}