阅读背景:

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();
        }
    }
}
namespace Case06_7



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: