大家好!我有一个程序可以计算数据库中注册的职位列中的所有总统。现在我数了数并将其放入我的文本框中。我想根据我的文本框中的值制作一个动态图片框。我该怎么做?
这是我现在的代码:
SqlConnection sc = new SqlConnection(@"Data Source=PYTHON-PC\PYTHON;Initial Catalog=DBVote;Persist Security Info=True;User ID=sa;Password=1234");
SqlCommand cmd;
public FVotingArea()
{
InitializeComponent();
}
DataTable dt = new DataTable();
PictureBox pb = new PictureBox();
RadioButton rb = new RadioButton();
private void FVotingArea_Load(object sender, EventArgs e)
{
sc.Open();
try
{
cmd = new SqlCommand("SELECT COUNT(Position) FROM TableVote WHERE Position='" + "President" + "'", sc);
Int32 count = (Int32)cmd.ExecuteScalar();
TxtCount.Text = count.ToString();
pb.Parent = this;
pb.BorderStyle = BorderStyle.FixedSingle;
pb.BringToFront();
pb.Location = new System.Drawing.Point(100, 50);
pb.Size = new System.Drawing.Size(112, 86);
pb.Name = "PresPicBox";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sc.Close();
}
}
我像这样存储我的图像:
public void Add()
{
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);
Param();
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();
}
}