Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a server machine(sql2008) and need to get data from 20 tables every sec.(table1,table2,ext..)

Used vs2015 and datagridview but local machines can't get data every sec. (crashed or lagged)

if i use 1 gridview it's work but i need to get data from 20 tables

how can i get 20 tables from sql on every sec.?

What I have tried:

timer interval=1000
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
       getdata(DataGridView1,table1)
   End Sub

Public Sub getdata(ByVal datagrid As Object, ByVal tableno As string)
       Dim Server As String = "server"
       Dim User As String = "sa"
       Dim Pass As String = "1231231"
       Dim Database As String = "database"


       Dim ay = "; "
       Dim DBConnection As String = ""
       DBConnection = DBConnection & "Provider=SQLOLEDB.1" & ay
       DBConnection = DBConnection & "Data Source=" & Server & ay
       DBConnection = DBConnection & "Initial Catalog=" & Database & ay
       DBConnection = DBConnection & "User ID=" & User & ay
       DBConnection = DBConnection & "Password=" & Pass & ";"

       Dim SQL As String

       SQL = "select * from " & tableno & ""

       Dim Conn As New ADODB.Connection()

       Dim rs As New ADODB.Recordset()

       Dim daTitles As New OleDbDataAdapter()

       Dim dsTitles As New DataSet("test")


       Conn.Open(DBConnection, "", "", -1)

       rs.Open(SQL, DBConnection, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)


       daTitles.Fill(dsTitles, rs, "setting")

       datagrid.DataSource = dsTitles.Tables(0)

       rs.ActiveConnection.close()
       rs.ActiveConnection = Nothing

       Conn.Close()
       Conn = Nothing

   End Sub
Posted
Updated 17-Jan-17 6:00am
Comments
Richard Deeming 17-Jan-17 11:56am    
1) Your application should NEVER connect to SQL as sa. This is the system administrator account, and should only ever be used for administration tasks. Your application should connect as a user which has only the permissions required to run your application.

2) You appear to be using ADODB. This is an obsolete COM-based technology, and will significantly slow down your code. You should be using ADO.NET[^] instead.
ADO.NET Overview[^]
ADO.NET Code Examples[^]
Michael_Davies 17-Jan-17 11:59am    
As per Richard's list with:

3. You set up a connection, open execute and close the connection for each table. You would save time if you opened loaded each table then closed. But as you are wanting the data every second open the connection for the duration of your program.
Yakup Yasin 17-Jan-17 12:48pm    
i tryed ado.net too. But nothing change. Ty

1 solution

Your "requirement" is ridiculous.

You're either going to generate 20 SQL queries to get the data you need or you're going to generate at least 1 query with a bunch of joins/unions and have to parse the returned result into a usable form in your app. That doesn't take into account the size of each record nor the number of records.

Sure, you can execute 20 queries in a second that don't really return anything, but you're leaving out the amount of data returned and the processing required on your side to display the data.

You cannot guarantee a 1 second turn around for all of these queries. The SQL Server can be busy doing other things and/or your client code will be busy processing the return data, binding it to their respective grids and handling user mouse and keyboard events and their processing requirements.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900