martes, 13 de diciembre de 2011

vb2010 COMO CARGAR UN DATAGRIDVIEW

Esta función nos permite cargar un datagridview en visual basic 2010.
'Funcion para cargar los registros consultados en datagridview
Public Sub loadRegistros(ByVal mySQL As String, ByVal grView As DataGridView)
Dim dt As New DataTable
Dim da As New Odbc.OdbcDataAdapter
Dim cmd As New Odbc.OdbcCommand
Try
Cursor.Current = Cursors.WaitCursor
cmd.Connection = conn
cmd.CommandText = mySQL
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
da.Fill(dt)
'Çargamos el Datagridview
grView.DataSource = dt
'Coloreamos intercaladamente el datagridview
grView.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
For i As Integer = 0 To grView.ColumnCount - 1
grView.AutoResizeColumn(i)
Next
grView.Refresh()
Cursor.Current = Cursors.Default
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
End Try
End Sub

No hay comentarios:

Publicar un comentario