我有我的图像的byte []数组,但我很难在图像控制中显示该图像。我不想使用httphandler,因为我在数据访问层中编写了所有与数据相关的代码,而httphandler存在于表示层中。
我的数据访问层代码是
public DataTable CheckUserID(string UserID)
{
try
{
var cn = ConfigurationManager.AppSettings["SGSDataBase_CN"];
con = new SqlConnection(cn);
DuplicateUser = new DataTable();
con.Open();
//com = new SqlCommand();
//com.Connection = con;
//com.CommandType = CommandType.Text;
//com.CommandText = "Select UserName from dms.Users_Table WHERE UserId = '" +UserID+ "'";
string query = "Select UserName, Password, ExpiredOn, IsAdmin, Department, Image from dms.Users_Table WHERE UserId = '" + UserID + "'";
SqlDataAdapter adap = new SqlDataAdapter();
adap.SelectCommand = new SqlCommand(query, con);
adap.Fill(DuplicateUser);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (com != null)
com.Dispose();
if (con != null)
con.Dispose();
com = null;
con = null;
}
return DuplicateUser;
}
上面的功能是检查用户是否存在,自动填写所有数据。
我的代码背后是:
protected void Txt_UserID_TextChanged(object sender, EventArgs e)
{
_objClsCreateUsers = new ClsCreateUsers();
userdata = new DataTable();
userdata = _objClsCreateUsers.CheckUserID(Txt_UserID.Text);
if (userdata.Rows.Count > 0)
{
//ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('UserID already exists')", true);
Txt_UserName.Text = userdata.Rows[0][0].ToString();
Txt_Password.Attributes["value"] = userdata.Rows[0][1].ToString();
Lst_Department.Text = userdata.Rows[0][4].ToString();
Txt_ExpiredOn.Attributes["value"] = userdata.Rows[0][2].ToString();
Lst_IsAdmin.Text = userdata.Rows[0][3].ToString();
//byte[] ImgArr = ((byte[])userdata.Rows[0][5]);
//string base64string = Convert.ToBase64String(ImgArr, 0, ImgArr.Length);
//Img_CreateUser.ImageUrl = "data:image/jpeg;base64," + base64string;
byte[] ImgArr = ((byte[])userdata.Rows[0][5]);
正如您所看到的,我使用了convert.tobase64string,但它只是在图像控件的右上角显示缩略图。
请建议一种可以在这里使用的方法。
提前致谢。