Gridview

时间:2015-07-08 08:34:05

标签: asp.net vb.net

我需要帮助,我需要在asp.net上使用vb.net创建Gridview(40行×10列),然后在gridview中生成并显示1到50之间的随机数,每2秒刷新一次。还需要一个按钮来打开和关闭刷新计时器。任何人都可以帮助或让我走向正确的方向吗?

1 个答案:

答案 0 :(得分:0)

此存储过程将为您提供一些亮点,并引导您前进的道路。我正在使用MSSQL 2014 Express,我希望您可以考虑从Access迁移到MSSQL。

CREATE PROCEDURE [dbo].[ProcGetRandoms] -- your procedure name
AS

BEGIN
DROP Table RANDOMS 

CREATE Table RANDOMS  --your columns
(
One varchar(20),
Two varchar(20),
Three varchar(20),
Four varchar(20),
Five varchar(20),
Six varchar(20),
Seven varchar(20),
Eight varchar(20),
Nine varchar(20),
Ten varchar(20),
)

DECLARE @row int = 0
WHILE @row < 40 BEGIN -- your desired Rows
SET @row = @row + 1

INSERT INTO [dbo].[RANDOMS]
       ([One]
       ,[Two]
       ,[Three]
       ,[Four]
       ,[Five]
       ,[Six]
       ,[Seven]
       ,[Eight]
       ,[Nine]
       ,[Ten])
 VALUES
        (--Using NewID() function for first 3 rows
         ABS(Checksum(NewID()) % 50)       
        , ABS(Checksum(NewID()) % 50)  
        , ABS(Checksum(NewID()) % 50)
        --random integer BETWEEN 0 AND 50  Using RAND() for the rest of the rows
        ,CONVERT(INT, (50+1)*RAND())
        ,CONVERT(INT, (50+1)*RAND())
        ,CONVERT(INT, (50+1)*RAND())
        ,CONVERT(INT, (50+1)*RAND())
        ,CONVERT(INT, (50+1)*RAND())
        ,CONVERT(INT, (50+1)*RAND())
        ,CONVERT(INT, (50+1)*RAND())
        )
END

-- to get the output that will be attached to your Gridview
SELECT * FROM RANDOMS

END

GO

- 关于计时器的代码隐藏('Handles Timer1.Tick)

    Dim sqlComRandoms As New SqlCommand
    With sqlComRandoms
        .CommandType = CommandType.StoredProcedure
        .Connection = conString
        .CommandText = "ProcGetRandoms"
    End With

    ' Create Data Adapter (Using the stored procedure Command created earlier)
    Dim DatadptRandoms As New SqlDataAdapter(sqlComRandoms)
    Dim datableRandoms As New DataTable

    DatadptRandoms.Fill(datableRandoms) 'data adapter to data table
    'Bind DataGridView using a Data Table intead of a Dataset
    DataGridView1.DataSource = datableRandoms

有了这个概念,我希望你能将它改编成MS Access并实现你的解决方案。随着时间的推移,有效的方法可以改进。