各位: 现界面上有"开始","停止"按钮, 按钮下面有个文本框,当点击"开始"按钮时,系统开始从数据库读取数据(手机号),并要求在界面上滚动显示(与电视上看到的产生幸运号码类似).单击停止时显示随机抽取的20个号码. 请问用C#如何实现这样的功能.

解决方案 »

  1.   

    sql server?select top 20 tel from yourtable order by newid()
      

  2.   

    先取20个 1至n范围的随机数 (n为记录总数)
    然后,从数据库中取出这些记录.要不然,随机找个位置(1至n-20),取出连续的20条记录.
      

  3.   

    随机生成20个ID号,然后根据ID号查询数据库就得到了
      

  4.   

    puny 这位兄弟,发给我~~~E-mail:[email protected]谢谢
      

  5.   

    吃饭的时候瞎写了一个,不过好烂,兄弟们别笑话.
    VS2005 
    -----------------------------------------------------------------------------------
    namespace Obtain
    {
        partial class Form1
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows 窗体设计器生成的代码        /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.lab1 = new System.Windows.Forms.Label();
                this.lab3 = new System.Windows.Forms.Label();
                this.lab5 = new System.Windows.Forms.Label();
                this.lab7 = new System.Windows.Forms.Label();
                this.lab9 = new System.Windows.Forms.Label();
                this.lab10 = new System.Windows.Forms.Label();
                this.lab6 = new System.Windows.Forms.Label();
                this.lab4 = new System.Windows.Forms.Label();
                this.lab8 = new System.Windows.Forms.Label();
                this.lab2 = new System.Windows.Forms.Label();
                this.lab11 = new System.Windows.Forms.Label();
                this.list1 = new System.Windows.Forms.ListBox();
                this.button1 = new System.Windows.Forms.Button();
                this.button2 = new System.Windows.Forms.Button();
                this.panel1 = new System.Windows.Forms.Panel();
                this.info1 = new System.Windows.Forms.Label();
                this.panel1.SuspendLayout();
                this.SuspendLayout();
                // 
                // lab1
                // 
                this.lab1.AutoSize = true;
                this.lab1.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab1.Location = new System.Drawing.Point(4, 4);
                this.lab1.Name = "lab1";
                this.lab1.Size = new System.Drawing.Size(36, 40);
                this.lab1.TabIndex = 0;
                this.lab1.Text = "0";
      

  6.   

    // 
                // lab3
                // 
                this.lab3.AutoSize = true;
                this.lab3.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab3.Location = new System.Drawing.Point(92, 4);
                this.lab3.Name = "lab3";
                this.lab3.Size = new System.Drawing.Size(36, 40);
                this.lab3.TabIndex = 2;
                this.lab3.Text = "0";
                // 
                // lab5
                // 
                this.lab5.AutoSize = true;
                this.lab5.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab5.Location = new System.Drawing.Point(180, 4);
                this.lab5.Name = "lab5";
                this.lab5.Size = new System.Drawing.Size(36, 40);
                this.lab5.TabIndex = 3;
                this.lab5.Text = "0";
                // 
                // lab7
                // 
                this.lab7.AutoSize = true;
                this.lab7.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab7.Location = new System.Drawing.Point(268, 4);
                this.lab7.Name = "lab7";
                this.lab7.Size = new System.Drawing.Size(36, 40);
                this.lab7.TabIndex = 4;
                this.lab7.Text = "0";
                // 
                // lab9
                // 
                this.lab9.AutoSize = true;
                this.lab9.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab9.Location = new System.Drawing.Point(356, 4);
                this.lab9.Name = "lab9";
                this.lab9.Size = new System.Drawing.Size(36, 40);
                this.lab9.TabIndex = 5;
                this.lab9.Text = "0";
                // 
                // lab10
                // 
                this.lab10.AutoSize = true;
                this.lab10.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab10.Location = new System.Drawing.Point(400, 4);
                this.lab10.Name = "lab10";
                this.lab10.Size = new System.Drawing.Size(36, 40);
                this.lab10.TabIndex = 6;
                this.lab10.Text = "0";
                // 
                // lab6
                // 
                this.lab6.AutoSize = true;
                this.lab6.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab6.Location = new System.Drawing.Point(224, 4);
                this.lab6.Name = "lab6";
                this.lab6.Size = new System.Drawing.Size(36, 40);
                this.lab6.TabIndex = 7;
                this.lab6.Text = "0";
                // 
                // lab4
                // 
      

  7.   

    this.lab4.AutoSize = true;
                this.lab4.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab4.Location = new System.Drawing.Point(136, 4);
                this.lab4.Name = "lab4";
                this.lab4.Size = new System.Drawing.Size(36, 40);
                this.lab4.TabIndex = 8;
                this.lab4.Text = "0";
                // 
                // lab8
                // 
                this.lab8.AutoSize = true;
                this.lab8.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab8.Location = new System.Drawing.Point(312, 4);
                this.lab8.Name = "lab8";
                this.lab8.Size = new System.Drawing.Size(36, 40);
                this.lab8.TabIndex = 9;
                this.lab8.Text = "0";
                // 
                // lab2
                // 
                this.lab2.AutoSize = true;
                this.lab2.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab2.Location = new System.Drawing.Point(48, 4);
                this.lab2.Name = "lab2";
                this.lab2.Size = new System.Drawing.Size(36, 40);
                this.lab2.TabIndex = 9;
                this.lab2.Text = "0";
                // 
                // lab11
                // 
                this.lab11.AutoSize = true;
                this.lab11.Font = new System.Drawing.Font("Arial", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lab11.Location = new System.Drawing.Point(444, 4);
                this.lab11.Name = "lab11";
                this.lab11.Size = new System.Drawing.Size(36, 40);
                this.lab11.TabIndex = 10;
                this.lab11.Text = "0";
                // 
                // list1
                // 
                this.list1.FormattingEnabled = true;
                this.list1.ItemHeight = 12;
                this.list1.Location = new System.Drawing.Point(12, 63);
                this.list1.Name = "list1";
                this.list1.Size = new System.Drawing.Size(183, 100);
                this.list1.TabIndex = 11;
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(224, 106);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(109, 57);
                this.button1.TabIndex = 12;
                this.button1.Text = "开始";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // button2
                // 
                this.button2.Location = new System.Drawing.Point(361, 106);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(109, 57);
                this.button2.TabIndex = 13;
                this.button2.Text = "停止";
                this.button2.UseVisualStyleBackColor = true;
                this.button2.Click += new System.EventHandler(this.button2_Click);
                // 
                // panel1
                // 
                this.panel1.Controls.Add(this.lab1);
                this.panel1.Controls.Add(this.lab3);
                this.panel1.Controls.Add(this.lab5);
                this.panel1.Controls.Add(this.lab7);
                this.panel1.Controls.Add(this.lab11);
                this.panel1.Controls.Add(this.lab9);
                this.panel1.Controls.Add(this.lab2);
                this.panel1.Controls.Add(this.lab10);
                this.panel1.Controls.Add(this.lab8);
                this.panel1.Controls.Add(this.lab6);
                this.panel1.Controls.Add(this.lab4);
                this.panel1.Location = new System.Drawing.Point(12, 8);
                this.panel1.Name = "panel1";
                this.panel1.Size = new System.Drawing.Size(492, 48);
                this.panel1.TabIndex = 14;
                // 
                // info1
                // 
                this.info1.AutoSize = true;
                this.info1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                this.info1.Location = new System.Drawing.Point(231, 71);
                this.info1.Name = "info1";
                this.info1.Size = new System.Drawing.Size(116, 19);
                this.info1.TabIndex = 15;
                this.info1.Text = "等待中.....";
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(526, 179);
                this.Controls.Add(this.info1);
                this.Controls.Add(this.panel1);
                this.Controls.Add(this.button2);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.list1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.Load += new System.EventHandler(this.Form1_Load);
                this.panel1.ResumeLayout(false);
                this.panel1.PerformLayout();
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion