Crear datatable vacio


/ Published in: VB.NET
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.