查询数据库表中的一列数据,以及如何查看多一列数据

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;




namespace 酒店信息管理3
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }


       
        SqlConnection conn;


        private void button3_Click(object sender, EventArgs e)
        {
            conn = new SqlConnection("server=localhost;database=HotelManage;Trusted_Connection=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select* from GuestInfo";
            cmd.CommandType = CommandType.Text;
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                listView3.Items.Add(sdr[1].ToString());//通过增加一列这行数据就可以多看一列数据
                listView3.Items.Add(sdr[2].ToString());
            }
            conn.Dispose();
            button3.Enabled = false;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_40307919/article/details/81054235
今日推荐