I have 2 questions.
First problem. When i have uploaded image in my database for specific user than my program working good and i successful log in , but if i dont have uploaded image i got this exception.
[
^]
And second question. How can i make it to hide image field if there is no image in specific column in database.
For example if i have 3 image fields in database and on my profile.aspx and only 1 image is uploaded , how i can hide other 2.
I hope you understand my concern(my english is not perfect).
What I have tried:
This is my code:
public partial class Control_Panel : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if(Session["User"] == null )
{
Response.Redirect("Login.aspx");
}
else
{
con.ConnectionString = "Data Source=JOSIPPC\\SQLEXPRESS;Initial Catalog=register;Integrated Security=True";
con.Open();
showdata();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["user"] = null;
Response.Redirect("Login.aspx");
}
public void showdata()
{
cmd.CommandText = "Select* from Table_1 where Email_id = '" +Session["user"]+ "'";
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(ds);
Label1.Text = ds.Tables[0].Rows[0]["First_Name"].ToString() + " "+ ds.Tables[0].Rows[0]["Last_Name"].ToString();
Label2.Text = ds.Tables[0].Rows[0]["Email_id"].ToString();
cmd.CommandText = "select Images from Table_1 where Email_id='" + Session["user"] + "'";
cmd.Connection = con;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
byte[] imgd = (byte[])dr["Images"];
string images = Convert.ToBase64String(imgd, 0, imgd.Length);
Image1.ImageUrl = "data:image/png;base64," + images;
}
}
else
{
}
}
}