惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
S
Securelist
小众软件
小众软件
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
O
OpenAI News
Cloudbric
Cloudbric
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
V2EX
PCI Perspectives
PCI Perspectives
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
M
MIT News - Artificial intelligence
V2EX - 技术
V2EX - 技术
阮一峰的网络日志
阮一峰的网络日志
Hacker News - Newest:
Hacker News - Newest: "LLM"
G
Google Developers Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
The Register - Security
The Register - Security
腾讯CDC
N
News and Events Feed by Topic
C
Check Point Blog
爱范儿
爱范儿
T
Tailwind CSS Blog
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
S
Schneier on Security
MyScale Blog
MyScale Blog
N
News | PayPal Newsroom
Recorded Future
Recorded Future
T
Tenable Blog
I
InfoQ
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Microsoft Security Blog
Microsoft Security Blog
Simon Willison's Weblog
Simon Willison's Weblog
Engineering at Meta
Engineering at Meta

博客园 - 寸芒

[原创]JScript学习摘要1 [随]程序设计模式的有趣解释-追MM [随]SQL Server 和ACCESS 、EXCEL 的数据转换 [原创]treeview简单根据数据库的数据,显示多级节点 [随]测试了下我的Blog价值(汗颜了) [随]C#轻松解决世纪迷题 [随]下了个windows live write 来玩玩 [随] 网站注册随机码的实现 [随]存储过程入门与提高 [原创]涂鸦事件 [随]c#.net常用函数和方法 [原创]到底调用哪个方法 [原创]浅要分析委托和事件 [原创]readonly 和const分析 [随]抽象基类与接口,共性与个性的选择 [原创]Box and Unbox [随]c#连接数据库 [随]八荣八耻 [原创]引用类型的转换之感想
[原创]作业:家庭消费管理程序,一点代码
寸芒 · 2007-08-27 · via 博客园 - 寸芒

最后的图:

802702

操作数据库的 DBconn.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
 
//数据类
namespace winfamily
{
    class DBconn
    {
      private OleDbConnection conn;
        //属性
        public OleDbConnection Conn
        {
            get { return conn; }
        }
        //连接数据库
        public  DBconn(string sql)
        {
            conn = new OleDbConnection(sql);
        }
        //取得数据集
        public DataSet getdb(string str)
        {  
            Conn.Open();
            OleDbDataAdapter oleda;
            oleda = new OleDbDataAdapter(str,Conn);
            DataSet ds = new DataSet();
            oleda.Fill(ds);
            //关闭
            Conn.Close();
            return ds;
        }
    }
}

------------------------------------------

应用程序的配置文件: App.conifg:

<?xml version="1.0" encoding="utf-8" ?>
    <add key="sql" value="provider=Microsoft.Jet.OLEDB.4.0;data source=db.mdb"/>
---------------------------
提交消费信息的代码(当然,最好使用参数插入到数据库):
//提交消费信息到数据库
    private void button1_Click(object sender, EventArgs e)
    {
        //得到数据库 表需要的数据
        string time = xfDatetime.Text;
        string type = xfType.SelectedItem.ToString();
        double money =double.Parse(xfMoney.Text);
        string address = xfAddress.Text;
        string person = xfPerson.Text;
        string info = xfInfo.Text;
        //插入数据
        string str = "insert into expenditure(消费日期,消费类别,消费金额,消费地点,消费者,备注说明) " +
            "values(#" + time + "#,'" + type + "'," + money + ",'" + address + "','" + person + "','" + info + "')";
        //执行SQL操作
        DBconn dbClass = new DBconn(sql);
        OleDbCommand command = new OleDbCommand(str, dbClass.Conn);
        dbClass.Conn.Open();
        command.ExecuteNonQuery();
        dbClass.Conn.Close();
        MessageBox.Show("提交成功!");
    }

---------

查询消费信息的代码:

//查询信息
    private void button2_Click(object sender, EventArgs e)
    {
        //查询语句
        string str = "select * from expenditure ";
        if (cxType.SelectedItem.ToString().Trim() != "")
            str +=  "where 消费类别='" + cxType.SelectedItem.ToString()+"'";
        if (cxperson.SelectedItem.ToString().Trim() != "")
            str +=  " and  消费者='" + cxperson.SelectedItem.ToString()+"'";
        str += " and  消费日期>= #" + cxBegintime.Value.ToShortDateString() + "#  and 消费日期<= #" + cxEndTime.Value.ToShortDateString() + "# ";
        MessageBox.Show(str);
        //执行查询 
        DBconn dbClass=new DBconn(sql);
        OleDbCommand olecommand = new OleDbCommand(str, dbClass.Conn);
        dbClass.Conn.Open();
        olecommand.ExecuteNonQuery();
        dbClass.Conn.Close();
        //显示查询
        DataSet ds = dbClass.getdb(str);
        dataGridView1.DataSource = ds.Tables[0];
       
    }
------------------------
一小段代码!