员工管理系统(2010-01-24 )

来源:互联网 发布:淘宝优惠群 编辑:程序博客网 时间:2024/05/18 05:06

 

第一次真正的用ACCESS数据库,挺担忧的。但真做起来,还没发现跟SQL Server 有什么区别。其中有一个问题。当我把ACCESS数据库的字段设置成为数字的时候。用强制类型转换一直失败,text.Text的内容和数据库里的内容就是不匹配。导致dataset填充一直失败。后来我干脆把员工编号的字段属性设置成为“文本”。程序运行没问题。但总觉得怪怪的。列出代码,什么时候解决掉。数据连接没有优化性能,甚至没有关闭连接。真丑陋。。。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace YGGLXT
{
    public partial class ygtdcx : Form
    {
        public ygtdcx()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text=="")
            { MessageBox.Show("请输入要查询信息!","提示"); }
            //按员工编号查询字符串
            String sql = "select XM AS 姓名,XB as 性别,SFZH AS 身份证号,XBM AS 现部门 from yuangong where YGBH='" + textBox1.Text.Trim() + "'";
            //按政治面貌查询字符串
            String zzmm = "select XM AS 姓名,XB as 性别,SFZH AS 身份证号,XBM AS 现部门,zzmm as 政治面貌 from yuangong where ZZMM='" + textBox1.Text.Trim() + "'";
            //按学历查询字符串
            String xueli = "select XM AS 姓名,XB as 性别,SFZH AS 身份证号,XBM AS 现部门,zzmm as 政治面貌 from yuangong where XL='" + textBox1.Text.Trim() + "'";
            //按姓名查询
            String xinming = "select XM AS 姓名,XB as 性别,SFZH AS 身份证号,XBM AS 现部门,zzmm as 政治面貌 from yuangong where XM='" + textBox1.Text.Trim() + "'";

            OleDbConnection ygcx = new OleDbConnection(@"Data Source=DB/YGGLDB.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
            ygcx.Open();
            DataSet ds = new DataSet();

 

            if (radioButton1.Checked == true)
                {
                OleDbDataAdapter ad = new OleDbDataAdapter(sql, ygcx);
                ad.Fill(ds, "yuangong");
                dataGridView1.AutoGenerateColumns = true;
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "yuangong";
                }
            else
                    if (radioButton2.Checked == true)
                    {
                        OleDbDataAdapter ad = new OleDbDataAdapter(zzmm, ygcx);
                        ad.Fill(ds, "yuangong");
                        dataGridView1.AutoGenerateColumns = true;
                        dataGridView1.DataSource = ds;
                        dataGridView1.DataMember = "yuangong";
                    }
                    else
                        if (radioButton3.Checked == true)
                        {
                            OleDbDataAdapter ad = new OleDbDataAdapter(xueli, ygcx);
                            ad.Fill(ds, "yuangong");
                            dataGridView1.AutoGenerateColumns = true;
                            dataGridView1.DataSource = ds;
                            dataGridView1.DataMember = "yuangong";
                        }
                        else
                            if (radioButton4.Checked == true)
                            {
                                OleDbDataAdapter ad = new OleDbDataAdapter(xinming, ygcx);
                                ad.Fill(ds, "yuangong");
                                dataGridView1.AutoGenerateColumns = true;
                                dataGridView1.DataSource = ds;
                                dataGridView1.DataMember = "yuangong";
                            }
                            else
                            { }
        }
    }
}

原创粉丝点击