• listView控件应用


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace WindowsFormsApplication7
    {
        class student
        {
            public string _code { get; set; }
            public string _name { get; set; }
            public bool _sex { get; set; }
            public DateTime _bithday { get; set; }
            public decimal _score { get; set; }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace WindowsFormsApplication7
    {
        public partial class Form1 : Form
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            public Form1()
            {
                InitializeComponent();
                conn = new SqlConnection("server=.;database=data0425;user=sa;pwd=123;");
                cmd = conn.CreateCommand();
            }
    
            private void listView1_SelectedIndexChanged(object sender, EventArgs e)
            {
                
     
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                List<student> list = new List<student>();
                cmd.CommandText = "select * from student";
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if(dr.HasRows)
                {
                    while(dr.Read())
                    {
                        student s = new student();
                        s._code = dr[0].ToString();
                        s._name = dr[1].ToString();
                        s._sex = Convert.ToBoolean(dr[2]);
                        s._bithday = Convert.ToDateTime(dr[3]);
                        s._score = Convert.ToDecimal(dr[4]);
    
                        list.Add(s);
    
                    }
                }
    
                conn.Close();
    
                foreach(student a in list)
                {
                    ListViewItem li = new ListViewItem();
                    li.Text = a._code;
    
                    li.SubItems.Add(a._name);
                    li.SubItems.Add((a._sex ? "" : ""));
                    li.SubItems.Add(a._bithday.ToString("yyyy年MM月dd日"));
                    li.SubItems.Add(a._score.ToString());
    
                    listView1.Items.Add(li);
                }
    
            }
        }
    }

  • 相关阅读:
    Linux里的2>&1究竟是什么
    表锁操作
    日志rsyslog
    计划任务at cron
    rpm包管理和源码包管理
    自建yum源(只演示nginx服务,其它都一样)
    软件包管理yum
    文件打包及压缩
    查找文件which locate find
    lsof恢复进程打开的文件
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5624058.html
Copyright © 2020-2023  润新知