第五天 直接从C#的项目开始吧

  今天正式上手c#的项目,不出所料,综合性很强,但是能学到很多东西,而且我发现果然有问题上google才是正确的选择,还好我英语比较好~~~还有42天了,加油啊!!!下面贴出今天的代码一边以后复习

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.SQLite;

namespace _01Review
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            //新建一个列表来存放数据库数据
            List<ManagerInfo> list = new List<ManagerInfo>();

            //从数据库表ManagerInfo中查询数据,将显示到DataGridView上
            string connStr = @"data source = C:\Users\Administrator\Desktop\ItcastCater.db;version=3;"; //记得那个data source啊,刚开始我以后路径不能包含中文,最后google才发现问题的所在。。。

            using (SQLiteConnection conn = new SQLiteConnection(connStr))//标准的引用SQLite的语句,不过我还是要补一下SQL Server的内容才行
            {
                //创建Command对象
                SQLiteCommand cmd = new SQLiteCommand("select * from ManagerInfo", conn);
                //打开链接
                conn.Open();
                //执行命令
                SQLiteDataReader reader = cmd.ExecuteReader();
                //读取
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        list.Add(new ManagerInfo()
                            {
                                Mid=Convert.ToInt32(reader["mid"]),
                                Mname=reader["mname"].ToString(),
                                Mpwd=reader["mpwd"].ToString(),
                                Mtype=Convert.ToInt32(reader["mtype"])
                            }
                            );
                    }
                }
                reader.Close();
                dataGridView1.DataSource = list;
            }
        }
    }
}

  

转载于:https://www.cnblogs.com/Martin-Ivy/p/5789430.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值