Ver Mensaje Individual
  #6 (permalink)  
Antiguo 12/09/2010, 03:38
winexim
 
Fecha de Ingreso: marzo-2007
Mensajes: 74
Antigüedad: 17 años, 1 mes
Puntos: 0
Respuesta: Mostrar datos en tiempo real en DataGridview otra forma

Crea otro programa para que lo pruebes

paso #1

Copiate este codigo y agregra un Datagridview a la forma
yo lo tengo en modulo1.vb para solo hacer una vez el diseno.



Mensaje_Error pon lo que tu quiera.




Public Sub Muestra_DVG(ByVal DGV As DataGridView, ByVal Tabla As String, ByVal Instruccion As String)
Try
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection(SerVer)
Dim DA As SqlClient.SqlDataAdapter
DA = New SqlClient.SqlDataAdapter(Instruccion, conn)
' crear conjunto de datos
Dim DS As DataSet
DS = New DataSet

Dim dt As DataTable = New DataTable(Tabla)
DA.Fill(DS)
DGV.DataSource = DS.Tables(0)

DGV.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point)
DGV.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.ControlDark
DGV.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
DGV.DefaultCellStyle.Font = New Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point)
DGV.DefaultCellStyle.BackColor = Color.Empty
DGV.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGoldenrodYellow
DGV.CellBorderStyle = DataGridViewCellBorderStyle.Single
DGV.GridColor = SystemColors.ControlDarkDark

DGV.AutoResizeColumns(DataGridViewAutoSizeColumnsM ode.AllCells)
DGV.AllowUserToAddRows = False

Catch ex As Exception
Mensaje_Error("datagrid ", Err.Number, Err.Description)
End Try
End Sub



Paso #2

hacer tu consulta
(con estas 2 lineas ya puedes crear cualquier datagrid)




private Sub Carga_Reloj()

q0 = "select max(HORA_INSERCION) as HORA_INSERCION , model from TAB_EVENTDATA_2 WHERE id_tab_files = " & Me.lb_id.Text & " group by model"

Muestra_DVG(DataGridView1, "TAB_EVENTDATA_2", q0 )
End Sub



Paso #3
poner el evento del timer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Carga_Reloj()
End Sub




Private Sub FrmReloj_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

SerVer = "Data Source=.\SQLEXPRESS;AttachDbFilename=c:\x.mdf;Inte grated Security=True;Connect Timeout=30;User Instance=True"
Carga_Reloj()

Timer1.Enabled = True
Timer1.Interval = 1000
End Sub


Yo lo tengo para recordarme mis llamadas que tengo que hacer y me funciona muy bien

En el formulario pones un control timer tambien



Espero te sirva.
saludos
Fernando.