如何将从包含一个列和多个行的查询中检索到的值放入文本框。我的意思是txtBox1将具有第一行的值,txtBox2将具有第二行的值,依此类推。我所知道的是如何检索每一列而不是行的值。
可能:
List<TextBox> allTextBoxes = this.Controls.OfType<TextBox>().ToList();
int current = -1;
using (var con = new MySqlConnection(Properties.Settings.Default.ConnectionString))
{
using (var cmd = new MySqlCommand("SELECT ColumnName FROM dbo.TableName", con))
{
con.Open();
using (var rd = cmd.ExecuteReader())
{
while (rd.Read() && ++current < allTextBoxes.Count)
{
allTextBoxes[current].Text = rd.GetString(0);
}
}
}
}
用this.Controls
包含所有TextBox
ES的容器控件替换。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句