一:动态获取数据库视图和存储过程信息
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";
}
}