Posted By

derebus on 07/01/10


Tagged

datatable vacio


Versions (?)

Crear datatable vacio


 / Published in: VB.NET
 

Funcion que crea un datatable vacio. Util para llenar un gridview. Ej. grvConvenio.DataSource = creaDtVacio(dtMiTabla, 3) Significa que el gridview sera llenado con la estructura del datatable "dtMiTabla" con 3 filas vacias asignadas

  1. Protected Function creaDtVacio(ByVal dt As DataTable, ByVal tam As Integer) As DataTable Implements IGestionEmpresa.creaDtVacio
  2. Try
  3. Dim dtvacio As New DataTable
  4. For j As Integer = 0 To dt.Columns.Count - 1
  5. dtvacio.Columns.Add(dt.Columns(j).ColumnName)
  6. Next
  7.  
  8. For i As Integer = 0 To tam
  9. Dim dr As DataRow
  10. dr = dtvacio.NewRow
  11. dtvacio.Rows.Add(dr)
  12. Next
  13.  
  14. Return dtvacio
  15. Catch ex As Exception
  16. Throw ex
  17. End Try
  18. End Function

Report this snippet  

You need to login to post a comment.