chaxun.cs

来自「火车票的销售系统」· CS 代码 · 共 67 行

CS
67
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace pwxt
{
    public partial class chaxun : Form
    {
        public chaxun()
        {
            InitializeComponent();
        }
        private void chaxun_Load(object sender, EventArgs e)
        {
            lv.View = View.Details;
            lv.Columns.Add("站名", lv.Width / 4, HorizontalAlignment.Left);
            lv.Columns.Add("车次", lv.Width / 4, HorizontalAlignment.Left);
            lv.Columns.Add("时间", lv.Width / 4, HorizontalAlignment.Left);
            lv.Columns.Add("价格", lv.Width / 4, HorizontalAlignment.Left);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            
            string arrivel=textBox1.Text;

            SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionstring"]);
            SqlCommand cmd=new SqlCommand ("Select * From LCtable Where 站名='"+arrivel+"'",conn);
            SqlDataReader odr = null;
            conn.Open();
            odr = cmd.ExecuteReader();
            if (odr != null)
            {
                while (odr.Read())
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = odr["站名"].ToString();
                    lvi.SubItems.Add(odr["车次"].ToString());
                    lvi.SubItems.Add(odr["时间"].ToString());
                    lvi.SubItems.Add(odr["价格"].ToString());
                    lv.Items.Add(lvi);
                }
            }
            else
                MessageBox.Show("目前还没有到达该目的站的列车", "error",MessageBoxButtons.OK);
            odr.Close();
            
            conn.Close();
            

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

       

       
        
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?