ShaileshY says:
Based on where condition that is session["user"] the data is fetched.
So you need to make sure child data is also fetched.
It looks like if the value of an image is manually inserted into database table, it will not display on page. So, I made a few changes to the page where child user registers. On the page load event of the child registration page, I called the Logo image of the principal user from database and displayed the Logo image on the child user registration page, so that when child user inserts his details, that Logo image will also be inserted. Then it will display on page when the child user logins.
Page Load Event of Child User Registration Page
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM Users WHERE Id = '" + Request.QueryString["Id"] + "'";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
sda.SelectCommand = cmd;
sda.Fill(ds, "detail");
if (ds.Tables[0].Rows.Count > 0)
{
NameID.Text = ds.Tables[0].Rows[0]["Name"].ToString();
labelid.Text = ds.Tables[0].Rows[0]["user_identity"].ToString();
byte[] bytes = (byte[])ds.Tables[0].Rows[0]["Logo"];
img11.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(bytes);
}
else
{
}
}
}
Then, when Child user wants to insert or register his details
protected void Button1_Click(object sender, EventArgs e)
{
string invitedBy = GetInvitedBy(Convert.ToString(Request.QueryString["Id"]));
if (mailtxtbx.Text != "" & pass.Text != "" & conpass.Text != "")
{
if (check1.Checked)
{
string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
byte[] image = Convert.FromBase64String(img11.ImageUrl.Replace("data:image/jpeg;base64,", ""));
using (SqlCommand cmd = new SqlCommand("INSERT INTO Users (email, pass, Name, CreatedDate, CreatedBy, LastLogin, Logo) VALUES(@email, @pass, @Name, @CreatedDate, @CreatedBy, @LastLogin, @Logo)"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@email", mailtxtbx.Text.Trim());
cmd.Parameters.AddWithValue("@pass", Encrypt(pass.Text.Trim()));
cmd.Parameters.AddWithValue("@Name", NameID.Text.Trim());
cmd.Parameters.AddWithValue("@CreatedDate", DateTime.UtcNow);
cmd.Parameters.AddWithValue("@CreatedBy", invitedBy);
cmd.Parameters.AddWithValue("@LastLogin", DateTime.UtcNow);
cmd.Parameters.AddWithValue("@Logo", image);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
Div1.Visible = true;
dvMessage.Visible = false;
lblMessage.Visible = false;
}
con.Close();
}
}
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.Text = "Please Check Box";
Div1.Visible = false;
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "*All Fields Are Required*";
lblsuccess.Visible = false;
Div1.Visible = false;
}
}
After that, when the child user login, the Logo image will display
public void Showdata1()
{
string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand
{
CommandText = "SELECT * FROM Users WHERE Id = '" + Session["user"] + "'",
Connection = con
};
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
sda.SelectCommand = cmd;
sda.Fill(ds, "detail");
if (ds.Tables[0].Rows.Count > 0)
{
user.Text = ds.Tables[0].Rows[0][1].ToString();
createby.Text = ds.Tables[0].Rows[0]["CreatedBy"].ToString();
labelid.Text = ds.Tables[0].Rows[0]["user_identity"].ToString();
Name.Text = ds.Tables[0].Rows[0][3].ToString();
byte[] bytes = (byte[])ds.Tables[0].Rows[0]["Logo"];
logoimg.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(bytes);
}
}
}