Hello Everyone! I have a problem displaying my images and information such as full name in my program. I have a for looped radiobutton and it counts as to how many candidates are running in a specific position. Example is "President".
Here is my code as of now :
cmd = new SqlCommand("SELECT COUNT(Position) FROM TableVote WHERE Position='" + "President" + "'", sc);
Int32 PresCount = (Int32)cmd.ExecuteScalar();
TxtPresCount.Text = PresCount.ToString();
//int lol = Convert.ToInt32(TxtPresCount.Text);
var panel = new FlowLayoutPanel();
panel.SuspendLayout();
panel.Size = new Size(600, 150);
panel.Location = new Point(50, 50);
panel.FlowDirection = FlowDirection.LeftToRight;
panel.AutoScroll = true;
panel.WrapContents = false;
this.Controls.Add(panel);
for (int i = 0; i < PresCount; ++i)
{
var radioButton = new RadioButton();
radioButton.Size = new Size(75, 75);
radioButton.CheckAlign = ContentAlignment.MiddleCenter;
radioButton.ImageAlign = ContentAlignment.MiddleCenter;
panel.Controls.Add(radioButton);
//radioButton.Image = Image.FromFile();
radioButton.ImageAlign = ContentAlignment.MiddleCenter;
radioButton.FlatStyle = FlatStyle.Flat;
}
panel.ResumeLayout();
as for the codes above, it counts all the President that is stored in the database. But my problem is, how do i put an image/Name that is stored in the database? Example i have 5 candidates running for the position of President, I want all the data to be in 5 radiobutton. How do i put the information into the radiobutton? Please help. :(
I add information using this code below :
sc.Open();
try
{
cmd = new SqlCommand("INSERT INTO TableVote (Position, FirstName, MiddleName, LastName, YearLevel, Course, SchoolYear, imgPath, imgImage) VALUES (@position, @firstname, @middlename, @lastname, @yearlevel, @course, @schoolyear, @imgpath, '" + _pb + "')", sc);
cmd.Parameters.AddWithValue("@position", _position);
cmd.Parameters.AddWithValue("@firstname", _firstname);
cmd.Parameters.AddWithValue("@middlename", _middlename);
cmd.Parameters.AddWithValue("@lastname", _lastname);
cmd.Parameters.AddWithValue("@yearlevel", _yearlevel);
cmd.Parameters.AddWithValue("@course", _course);
cmd.Parameters.AddWithValue("@schoolyear", _schoolyear);
cmd.Parameters.AddWithValue("@imgpath", _imgpath);
int res = cmd.ExecuteNonQuery();
if(res > 0)
{
MessageBox.Show("Data Stored Successfully!");
FAdminSet._cleardata = cleardata;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sc.Close();
}
this is my database :