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

namespace WindowsApplication1
{
    public partial class Form010 : Form
    {
        public Form010()
        {
            InitializeComponent();
           
        }

        private void Form010_Load(object sender, EventArgs e)
        {
            
            
        }
        /// <summary>
        /// 鼠标单击事件，显示数据库读取的进度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //本次为MS SQLserver数据库本机链接，测试数据库为NorthWind，测试的表为Orders
            //默认链接用户名称sa，登录密码为空。
            //请在头部引用MS SQLserver操作类库：using System.Data.SqlClient;
            string sqlstring = "Data Source=(local);Initial Catalog=NorthWind;User ID=sa";
            //数据库连接字符串
            SqlConnection conn = new SqlConnection(sqlstring);
            //数据表查询字符串
            string sql = "select * from Orders";
            //定义SqlCommand对象，命名为cmd
            SqlCommand cmd = new SqlCommand(sql, conn);
            //定义SqlDataAdapter对象，命名为adp
            SqlDataAdapter adp = new SqlDataAdapter();
            //将SQL查询命令结果缓冲至SqlDataAdapter对象
            adp.SelectCommand = cmd;
            //定义DataSet对象，命名为ds
            DataSet ds = new DataSet();
            //将缓冲至SqlDataAdapter对象的数据填充至DataSet对象，进行离线数据处理
            adp.Fill(ds);
            //释放数据库连接资源
            conn.Dispose();
            conn.Close();
            conn = null;
            //设置进度条控件属性
            toolStripProgressBar1.Minimum = 0;//进度条控件最小值为0
            toolStripProgressBar1.Maximum = ds.Tables[0].Rows.Count;//进度条控件最大值为读取表内容行数

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                toolStripProgressBar1.Value++;//每次读取数据表，进度条值加1
                Application.DoEvents();//当前程序处理消息队列内容
            }

        }

             
    }
}