【发布时间】:2017-05-13 11:28:23
【问题描述】:
有没有办法将数据库中的数据显示到文本框中,但是每次单击 NEXT 时都会显示新行。我有这段代码,但它不像我想要的那样工作,因为它将所有数据显示到一个文本框中,而不是一次显示一行。
private void buttonNEXT_Click(object sender, EventArgs e)
{
SQLiteConnection conn = new SQLiteConnection("data source = people.sqlite");
conn.Open();
SQLiteCommand com = new SQLiteCommand(conn);
com.CommandText = "SELECT id, name, surname FROM people;";
SQLiteDataReader reader = com.ExecuteReader();
while (reader.Read())
{
textBox1.Text += reader["id"].ToString();
textBox2.Text += reader["name"].ToString();
textBox3.Text += reader["surname"].ToString();
}
conn.Close();
}
【问题讨论】:
-
WinForms?您可能需要 BindingNavigator。但是,如果您只想转发访问,则可以使用 Reader - 只需在 click 事件之外执行您的阅读器并将其存储在变量中,然后在每次单击按钮时调用 Read,而不是“while(reader.Read())”