01/09/2010, 08:07
|
| | Fecha de Ingreso: julio-2008
Mensajes: 26
Antigüedad: 16 años, 4 meses Puntos: 0 | |
Respuesta: Mostrar datos en tiempo real en DataGridview este es el código
Código:
Sub ciclico()
Try
hilo = New Thread(New ThreadStart(AddressOf actualizar_grids))
If hilo.IsAlive = False Then
hilo.Start()
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Sub actualizar_grids()
If TextBox1.Text <> "" Then
MODEL = TextBox1.Text
Try
Dim dr As SqlDataReader
Dim cmdDB As SqlCommand
q0 = "select max(HORA_INSERCION) as HORA_INSERCION , model from TAB_EVENTDATA_2 WHERE id_tab_files = " & Me.lb_id.Text & " group by model"
If c_grid.State = ConnectionState.Closed Then
c_grid.ConnectionString = My.Settings.cadena_conexion
c_grid.Open()
End If
If c_grid.State = ConnectionState.Open Then
cmdDB = New SqlCommand(q0, c_grid)
dr = cmdDB.ExecuteReader
If dr.Read Then
hora = dr.GetValue(0).ToString
new_model = dr.GetValue(1).ToString
dr.Close()
If MODEL = new_model Then
Try
q1 = "select ..."
q2 = "select ..."
q3 = "select ..."
q4 = "select ..."
If c_grid.State = ConnectionState.Open Then
Control.CheckForIllegalCrossThreadCalls = False
Try
ds1 = New DataSet
da1 = New SqlDataAdapter(q1, c_grid)
da1.FillSchema(ds1, SchemaType.Source, "error_code")
da1.Fill(ds1, "error_code")
'BindingSource1 = New BindingSource()
BindingSource1.DataSource = ds1
BindingSource1.DataMember = "error_code"
Try
DataGridView1.DataSource = BindingSource1
Catch ex As Exception
Debug.Print(ex.Message)
Finally
DataGridView1.Refresh()
End Try
Catch ex As Exception
Debug.Print(ex.Message)
Finally
End Try
Try
ds2 = New DataSet
da2 = New SqlDataAdapter(q2, c_grid)
da2.FillSchema(ds2, SchemaType.Source, "Feeder")
da2.Fill(ds2, "Feeder")
'BindingSource2 = New BindingSource()
BindingSource2.DataSource = ds2
BindingSource2.DataMember = "Feeder"
Try
DataGridView2.DataSource = BindingSource2
Catch ex As Exception
Debug.Print(ex.Message)
Finally
DataGridView2.Refresh()
End Try
Catch ex As Exception
Debug.Print(ex.Message)
Finally
End Try
Try
ds3 = New DataSet
da3 = New SqlDataAdapter(q3, c_grid)
da3.FillSchema(ds3, SchemaType.Source, "Nozzle")
da3.Fill(ds3, "Nozzle")
'BindingSource3 = New BindingSource()
BindingSource3.DataSource = ds3
BindingSource3.DataMember = "Nozzle"
Try
DataGridView3.DataSource = BindingSource3
Catch ex As Exception
Debug.Print(ex.Message)
Finally
DataGridView3.Refresh()
End Try
Catch ex As Exception
Debug.Print(ex.Message)
Finally
End Try
Try
ds4 = New DataSet
da4 = New SqlDataAdapter(q4, c_grid)
da4.FillSchema(ds4, SchemaType.Source, "ref")
da4.Fill(ds4, "ref")
'BindingSource4 = New BindingSource()
BindingSource4.DataSource = ds4
BindingSource4.DataMember = "ref"
Try
DataGridView4.DataSource = BindingSource4
Catch ex As Exception
Debug.Print(ex.Message)
Finally
DataGridView4.Refresh()
End Try
Catch ex As Exception
Debug.Print(ex.Message)
Finally
End Try
End If
Catch ex As Exception
Debug.Print(ex.Message)
Finally
End Try
Else
'no son iguales generar reporte
Me.TextBox1.Text = new_model
End If
Else
Control.CheckForIllegalCrossThreadCalls = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = False
DataGridView1.DataSource = Nothing
DataGridView2.DataSource = Nothing
DataGridView3.DataSource = Nothing
DataGridView4.DataSource = Nothing
DataGridView1.Refresh()
DataGridView2.Refresh()
DataGridView3.Refresh()
DataGridView4.Refresh()
End If
c_grid.Close()
End If
Catch ex As Exception
Debug.Print(ex.Message)
Finally
End Try
Try
Application.DoEvents()
System.Threading.Thread.Sleep(20000) ' Sleep for 20 second
Catch ex As Exception
Debug.Print(ex.Message)
Finally
ciclico()
End Try
End If
End Sub
|