• 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);
                }
    
            }
        }
    }

  • 相关阅读:
    委托
    反射
    ADO.net五大对象
    DNS协议详解
    FTP协议详解
    .Net 多线程 异步编程 Await、Async和Task
    AsnycLocal与ThreadLocal
    Angular 6.X CLI(Angular.json) 属性详解
    Angular Npm Package.Json文件详解
    Npm常用命令整理
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5624058.html
Copyright © 2020-2023  润新知