private void button1_Click(object sender, EventArgs e)
{
try
{
string MyConnection2 = "datasource = 127.0.0.1;port=3306;username = root;password =; database = test123; SslMode=None ;Convert Zero Datetime=True";
int txtno = int.Parse(textBox1.Text);
int pointX = 30;
int pointY = 40;
panel2.Controls.Clear();
for (int i = 0; i < txtno; i++)
{
TextBox a = new TextBox();
a.Text = (i + 1).ToString();
a.Location = new Point(pointX, pointY);
panel2.Controls.Add(a);
panel2.Show();
pointY += 20;
}
string Query = "select task_comment from test123.task_comment where task_id ='" + textBox1.Text + "'";
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
MyAdapter.SelectCommand = MyCommand2;
MyConn2.Close();
MySqlDataReader MyReader2;
MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader();
while (MyReader2.Read())
{
txtno = Convert.ToInt32(MyReader2["task_comment"].ToString());
}
MyConn2.Close(); //Connection closed here
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
2条答案
按热度按时间dgsult0t1#
试试这个:
希望这有帮助!
q5iwbnjs2#
假设您将从mysql检索到的数据放在一个具有propertis id和name的对象列表中,那么您将对它们进行循环,并创建一个textbox并将其添加到表单中: