21
2012
04

cmd.ExecuteScalar为初始化

            object num = null;
            SqlCommand cmd = null;
            try
            {
                string sql = string.Format("select COUNT(*) from {0}", tableName);  //查询数据库中某个表的记录数               
                if (connection.State == ConnectionState.Closed)  //查看数据库是否已经打开,如果已经关闭则打开数据库连接
                {
                    connection.Open();
                }
                cmd = new SqlCommand(sql, connection);   //执行查询已经
                cmd.CommandTimeout = 600;   //执行超时时间为600秒
                if (null != cmd.ExecuteScalar())    //执行的结果不为空
                {
                    //隐藏登录窗口     this.Visible=false;
                    //创建并打开主界面     Main main=new Main();
                    main.Tag = this.FindForm();
                    SqlDataReader dr;
                    cmd.CommandText = sql;
                    dr = cmd.ExecuteReader();
                    dr.Read();
                    main.toolStripStatusLabel2.Text = name.Text.Trim();
                    main.ShowDialog();
                }
            }
            catch (Exception ex)
            {
            }

« 上一篇下一篇 »

评论列表:

学习一下了

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。