C# winform窗体技术点二

一:动态获取数据库视图和存储过程信息

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

        SqlConnection con;               //定义SqlConnection对象实例     
        SqlDataAdapter ada;               //定义SqlDataAdapter对象实例   
        DataSet ds;                     //定义DataSet对象实例 
 

        private void button1_Click(object sender, EventArgs e)
        {
            //生成连接数据库字符串
            string ConStr = "server=(local);user id=sa;pwd=sql;database=FAIS";
            //定义SqlConnection对象实例  
           con = new SqlConnection(ConStr);
            //显示视图中所有数据信息
            string SqlStr = "select name as 视图名称,crdate as 创建日期, refDate as 最后修改日期 from Sysobjects where xtype = 'v' ";
           ada = new SqlDataAdapter(SqlStr, con);
           ds = new DataSet();    //定义DataSet对象实例
            ada.Fill(ds);
            //连接数据表格,显示数据  
            this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            con.Open();
            string SqlStr = "select name as 存储过程名称,crdate as 创建日期, refDate as 最后修改日期 from Sysobjects where xtype = 'p' ";
            ada = new SqlDataAdapter(SqlStr, con);
            ds = new DataSet();    //定义DataSet对象实例
            ada.Fill(ds);
            //连接数据表格,显示数据  
            this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }
    }
}

如图:
在这里插入图片描述

二:监视文件系统变化情况

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

        private void button1_Click_1(object sender, System.EventArgs e)
        {//浏览文件夹
            if (this.folderBrowserDialog2.ShowDialog() == DialogResult.OK)
            {
                if (this.folderBrowserDialog2.SelectedPath.Trim() != "")
                {
                    this.textBox1.Text = this.folderBrowserDialog2.SelectedPath.Trim();
                }
            }
        }

        private void button2_Click(object sender, System.EventArgs e)
        {//开始监视文件系统变化情况
            if (!System.IO.Directory.Exists(this.textBox1.Text))
            {
                MessageBox.Show("选择的不是一个文件夹"
                , "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.fileSystemWatcher2.Path = this.textBox1.Text;
            MessageBox.Show(this.textBox1.Text + "已经处于被监视状态!
            ", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }
      
        private void fileSystemWatcher2_Created(object sender, System.IO.FileSystemEventArgs e)
        {//新增
            this.richTextBox1.Text += "\n刚刚新增:" + e.FullPath.ToString();
        }

        private void fileSystemWatcher2_Deleted(object sender, System.IO.FileSystemEventArgs e)
        {//删除
            this.richTextBox1.Text += "\n刚刚删除:" + e.FullPath.ToString();
        }

        private void fileSystemWatcher2_Renamed(object sender, System.IO.RenamedEventArgs e)
        {//更名
            this.richTextBox1.Text += "\n刚刚更名:" + e.FullPath.ToString();
        }

       

        private void fileSystemWatcher2_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            //发生改变
            this.richTextBox1.Text += e.FullPath.ToString() + "  发生改变!\n";
        }
    }

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值