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

推荐订阅源

Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Latest
Security Latest
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
J
Java Code Geeks
P
Privacy International News Feed
阮一峰的网络日志
阮一峰的网络日志
S
Schneier on Security
博客园 - 聂微东
Project Zero
Project Zero
美团技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 司徒正美
O
OpenAI News
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
SecWiki News
SecWiki News
月光博客
月光博客
S
Security Affairs
The GitHub Blog
The GitHub Blog
P
Privacy & Cybersecurity Law Blog
S
Secure Thoughts
V
V2EX
S
Securelist
F
Fortinet All Blogs
W
WeLiveSecurity
D
Docker
博客园 - 三生石上(FineUI控件)
Simon Willison's Weblog
Simon Willison's Weblog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
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];
       
    }
------------------------
一小段代码!