. The black box is a usercontrol.
Usercontrol Code
string b = "";
public string ID
{
set { b = value; }
}
public void sample()
{
textBox1.Clear();
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select LastName, Image from Employee where ID = @a", myDatabaseConnection))
{
SqlCommand.Parameters.AddWithValue("@a", b);
DataSet DS = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(SqlCommand);
da.Fill(DS, "Images");
var imagesTable = DS.Tables["Images"];
var imagesRows = imagesTable.Rows;
var count = imagesRows.Count;
if (count <= 0)
return;
var imageColumnValue =
imagesRows[count - 1]["Image"];
if (imageColumnValue == DBNull.Value)
return;
var data = (Byte[])imageColumnValue;
using (var stream = new MemoryStream(data))
{
pictureBox1.Image = Image.FromStream(stream);
}
}
}
}
public void getname()
{
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select LastName from Employee where ID = @a", myDatabaseConnection))
using (SqlDataAdapter da = new SqlDataAdapter(SqlCommand))
{
SqlCommand.Parameters.AddWithValue("@a", b);
SqlDataReader DR1 = SqlCommand.ExecuteReader();
if (DR1.Read())
{
textBox1.Text = DR1.GetString(DR1.GetOrdinal("LastName")).ToString();
}
}
}
}
Form Code
public string ID
{
get { return textBox1.Text; }
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
userControl21.ID = ID;
userControl21.sample();
userControl21.getname();
}
Using the code above I can display a single record to the usercontrol. How i can display a number of usercontrol based on the number of records in the database with their picture and name? For example I have 7 records in the database, the form will display 7 usercontrols. And when I click or select a usercontrol more information such as Address, Contacts, Etc will be display in my form. If the records in the database is too many to fit in the form there will be a vertical or horizontal scroll bar. Give me some code :)
What is the best container to display the usercontols that can have scroll bar? a panel, groupbox or anything?
This must be the sample output. .