如何根据用户的预订显示预订

时间:2019-11-25 17:40:13

标签: c# winforms

如何根据登录用户显示预订数据?

这是登录表单:

login page

这是预订表格

view bookings

代码如下:

login f1 = new login();
string userName = f1.textBox1.Text;
string connectionString = "datasource=127.0.0.1;port=3306;username=root;password=;database=project_visprog";
string query = "SELECT src, dst, stime FROM bookings WHERE loginid = '" + userName + "'";
/* string query = "SELECT src, dst, stime FROM bookings";*/
MySqlConnection dbcon = new MySqlConnection(connectionString);
MySqlCommand commandDatabase = new MySqlCommand(query, dbcon);
commandDatabase.CommandTimeout = 60;
MySqlDataReader reader;
try
{
  dbcon.Open();
  reader = commandDatabase.ExecuteReader();
  if (reader.HasRows)
  {
    while (reader.Read())
    {
      ListViewItem lst = new ListViewItem(reader.GetString(0).ToString());
      lst.SubItems.Add(reader.GetString(1));
      lst.SubItems.Add(reader.GetString(2));
      listView1.Items.Add(lst);
    }
    reader.Close();
    dbcon.Close();
  }
}
catch (Exception w)
{
  MessageBox.Show(w.Message);
}
label1.Text = usr;
listView1.GridLines = true;
listView1.View = View.Details;
listView1.Columns.Add("Source", 100);
listView1.Columns.Add("Destination", 100);
listView1.Columns.Add("Time", 100);`

0 个答案:

没有答案