用于读取sql实例的Progressbar [英] Progressbar for read sql instance

查看:97
本文介绍了用于读取sql实例的Progressbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有2个表格

LoginFrm和Splash_frm

LoginFrm and Splash_frm

in splash_frm我有一个进度条,2个sql命令,sql连接,列表框和2个组合框

in splash_frm I have a progressbar,2 sql command,sql connection,listbox and 2 combobox

我想在Splash_frm显示时,获取sql实例,从数据库表中获取用户名和密码所以拿一些时间和进度条显示进度。这是我的代码,但我不知道如何使用进度条。

I want when Splash_frm is show,get sql instance,get username and passwords from the table of database so take a few time and progressbar show the progress.that's my code but I don't know how use the progressbar.

我怎么做?

thx for all

thx for all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
namespace fedelak.forms
{
   
    public partial class LoginFrm : Form
    {
        
        public LoginFrm()
        {
            InitializeComponent();
        }
         main_form main_frm = new main_form();
        
        public string operator1;
        public string mgr1;
        public string mgr2;
        public string pass1;
        public string pass2;
        public string pass3;
        /// <summary>
        /// Get Username
        /// </summary>
        private void get_username()
        {
            sqlUserCmd.CommandText = "select user_name from user_table";
            sqlUserCmd.Connection = sqlConnection1;
            sqlConnection1.Open();
            SqlDataReader dr = sqlUserCmd.ExecuteReader();
            while (dr.Read())
                selectUsername.Items.Add(dr.GetValue(0).ToString());
            mgr1 = selectUsername.Items[0].ToString();
            mgr2 = selectUsername.Items[1].ToString();
            operator1 = selectUsername.Items[2].ToString();
            sqlConnection1.Close();
        }
        /// <summary>
        /// Get Password
        /// </summary>
        private void get_pass()
        {
            sqlPassCmd.CommandText = "select password from user_table";
            sqlPassCmd.Connection = sqlConnection1;
            sqlConnection1.Open();
            SqlDataReader dr = sqlPassCmd.ExecuteReader();
            while (dr.Read())
                selectPass.Items.Add(dr.GetValue(0).ToString());
            pass1 = selectPass.Items[0].ToString();
            pass2 = selectPass.Items[1].ToString();
            pass3 = selectPass.Items[2].ToString();
            sqlConnection1.Close();
        }
        /// <summary>
        /// Read User name and password from database
        /// </summary>
        private void get_data()
        {
            string get_pc, get_server;
            DataTable dataTable = SmoApplication.EnumAvailableSqlServers(true);
            listBox1.ValueMember = "Name";
            listBox1.DataSource = dataTable;
            get_server = listBox1.SelectedValue.ToString();
            get_pc = Environment.MachineName;
            sqlConnection1.ConnectionString = "Data Source=" + get_server + ";Initial Catalog=fedelak_product;Integrated Security=True";
            //MessageBox.Show(sqlConnection1.ConnectionString.ToString());            
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            
            this.ActiveControl = User;//User is my textbox
            get_data();
            get_username();
            get_pass();
        }

推荐答案

进度条有点矫枉过正。为什么不在启动进程时将鼠标指针设置为沙漏,并在进程完成时将鼠标指针设置恢复正​​常?这也是表明事情正在发生的一种方式。
The progressbar is kind of overkill. Why don't you just set the Mouse Pointer to an hourglass when starting the process and set the Mouse Pointer back to normal when the process completes? That's a way too to show that something is happening.


这篇关于用于读取sql实例的Progressbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆