I have byte[] array of my image but i am having a hard time in displaying that image in image control. I don't want to use httphandler because i'm writing all my data related code in Data access layer and httphandler is present in presentation layer.
My Data access layer code is
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;
}
Above function is checking that if the user is present, auto fill all it's data.
My code behind is:
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]);
As you can see i have used convert.tobase64string but it is just showing a thumbnail in the upper right corner of the image control.
Please suggest a method which can be used here.
Thanks in advance.