Foros del Web » Programación para mayores de 30 ;) » .NET »

como pasar todo el contenido datagreedview a una variable

Estas en el tema de como pasar todo el contenido datagreedview a una variable en el foro de .NET en Foros del Web. necesito pasar todo el contenido de un datagreedviw a una variable, con el fin de volvera mostrar lo q habia sin necesidad de volver hacer ...
  #1 (permalink)  
Antiguo 14/02/2011, 09:32
 
Fecha de Ingreso: enero-2011
Ubicación: La Serena
Mensajes: 28
Antigüedad: 13 años, 3 meses
Puntos: 0
como pasar todo el contenido datagreedview a una variable

necesito pasar todo el contenido de un datagreedviw a una variable, con el fin de volvera mostrar lo q habia sin necesidad de volver hacer la consulta a la bd ya que se de mora mucho por la canidad de datos q muestro... he estado intentando con lo sigueinte pero no funciona xD

Dim gt As DataSet
gt = Me.DataGridView1


por favor si alguien me puede ayudar
  #2 (permalink)  
Antiguo 14/02/2011, 09:40
 
Fecha de Ingreso: febrero-2010
Ubicación: México
Mensajes: 738
Antigüedad: 14 años, 2 meses
Puntos: 37
Respuesta: como pasar todo el contenido datagreedview a una variable

Hola Oscar_Santander

Como llenas ese DataGridView?

Saludos!
__________________
http://ka0stj.wordpress.com/
  #3 (permalink)  
Antiguo 14/02/2011, 09:45
 
Fecha de Ingreso: enero-2011
Ubicación: La Serena
Mensajes: 28
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: como pasar todo el contenido datagreedview a una variable

Código vb:
Ver original
  1. Dim conectar As New OleDbConnection(conexion)
  2.         conectar.Open()
  3.         'borra las columnas del datagreedview
  4.        Me.DataGridView1.DataSource = ""
  5.         Me.DataGridView1.Columns.Clear()
  6.         If Me.ComboBox1.Text <> "Seleccionar Establecimiento" And Me.ComboBox2.Text <> "" Then
  7.             Dim mosene As New OleDb.OleDbDataAdapter("select DISTINCT (d.CodigoPrestacion) as Código, p.NOMBRE_PRESTACION as Prestación, p.REM_PRESTACION as Rem, p.SECCION as Sección, d.Col01 as Enero from DatosSerieA d, PRESTACIONES p where d.CodigoPrestacion=p.CODIGO_PRESTACION and d.IdEstablecimiento='" & Me.Label7.Text & "' and d.Mes=1 and Ano=" & Me.ComboBox2.Text & "", conectar)
  8.             Dim datos As New DataSet
  9.             mosene.Fill(datos)
  10.             Me.DataGridView1.DataSource = datos.Tables(0)
  11.            
  12.             Dim pb As ToolStripProgressBar = MDIParent1.ToolStripProgressBar1
  13.             pb.Visible = True
  14.             pb.Maximum = Me.DataGridView1.RowCount - 1
  15.             pb.Step = 1
  16.  
  17.  
  18.             '--------------------------------------------------------------------
  19.            'crea las columnas del datagredview
  20.            '--------------------------------------------------------------------
  21.            Me.DataGridView1.Columns.Add("Febrero", "Febrero")
  22.             Me.DataGridView1.Columns.Add("Marzo", "Marzo")
  23.             Me.DataGridView1.Columns.Add("Abril", "Abril")
  24.             Me.DataGridView1.Columns.Add("Mayo", "Mayo")
  25.             Me.DataGridView1.Columns.Add("Junio", "Junio")
  26.             Me.DataGridView1.Columns.Add("Julio", "Julio")
  27.             Me.DataGridView1.Columns.Add("Agosto", "Agosto")
  28.             Me.DataGridView1.Columns.Add("Septiembre", "Septiembre")
  29.             Me.DataGridView1.Columns.Add("Octubre", "Octubre")
  30.             Me.DataGridView1.Columns.Add("Noviembre", "Noviembre")
  31.             Me.DataGridView1.Columns.Add("Diciembre", "Diciembre")
  32.             Me.DataGridView1.Columns.Add("Total", "Total")
  33.             '--------------------------------------------------------------------
  34.            '--------------------------------------------------------------------
  35.  
  36.             '--------------------------------------------------------------------
  37.            'inserta el valor corespondiente a cada mes
  38.            '--------------------------------------------------------------------
  39.            For i As Integer = 0 To Me.DataGridView1.RowCount - 2
  40.                 Dim feb As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 2 and Ano=" & Me.ComboBox2.Text & "", conectar)
  41.                 Dim mar As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 3 and Ano=" & Me.ComboBox2.Text & "", conectar)
  42.                 Dim abr As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 4 and Ano=" & Me.ComboBox2.Text & "", conectar)
  43.                 Dim may As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 5 and Ano=" & Me.ComboBox2.Text & "", conectar)
  44.                 Dim jun As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 6 and Ano=" & Me.ComboBox2.Text & "", conectar)
  45.                 Dim jul As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 7 and Ano=" & Me.ComboBox2.Text & "", conectar)
  46.                 Dim ago As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 8 and Ano=" & Me.ComboBox2.Text & "", conectar)
  47.                 Dim sep As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 9 and Ano=" & Me.ComboBox2.Text & "", conectar)
  48.                 Dim oct As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 10 and Ano=" & Me.ComboBox2.Text & "", conectar)
  49.                 Dim nov As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 11 and Ano=" & Me.ComboBox2.Text & "", conectar)
  50.                 Dim dic As New OleDb.OleDbCommand("select Col01 from DatosSerieA where CodigoPrestacion='" & Me.DataGridView1.Rows(i).Cells("Código").Value & "' and IdEstablecimiento='" & Me.Label7.Text & "' and Mes= 12 and Ano=" & Me.ComboBox2.Text & "", conectar)
  51.  
  52.                 Try
  53.                     Me.DataGridView1.Item(5, i).Value = feb.ExecuteScalar()
  54.                     Me.DataGridView1.Item(6, i).Value = mar.ExecuteScalar()
  55.                     Me.DataGridView1.Item(7, i).Value = abr.ExecuteScalar()
  56.                     Me.DataGridView1.Item(8, i).Value = may.ExecuteScalar()
  57.                     Me.DataGridView1.Item(9, i).Value = jun.ExecuteScalar()
  58.                     Me.DataGridView1.Item(10, i).Value = jul.ExecuteScalar()
  59.                     Me.DataGridView1.Item(11, i).Value = ago.ExecuteScalar()
  60.                     Me.DataGridView1.Item(12, i).Value = sep.ExecuteScalar()
  61.                     Me.DataGridView1.Item(13, i).Value = oct.ExecuteScalar()
  62.                     Me.DataGridView1.Item(14, i).Value = nov.ExecuteScalar()
  63.                     Me.DataGridView1.Item(15, i).Value = dic.ExecuteScalar()
  64.                 Catch ex As Exception
  65.                     MsgBox(ex.ToString)
  66.                 End Try
  67.                 pb.Value += 1
  68.             Next
  69.             '--------------------------------------------------------------------
  70.            '--------------------------------------------------------------------
  71.  
  72.             '--------------------------------------------------------------------
  73.            'suma las columnas de enero a diciembre
  74.            '--------------------------------------------------------------------
  75.            Dim suma As Integer = 0
  76.             For i As Integer = 0 To DataGridView1.Rows.Count - 2
  77.                 For x As Integer = 4 To DataGridView1.Columns.Count - 2
  78.                     If IsDBNull(DataGridView1.Rows(i).Cells(x).Value) Then
  79.  
  80.                     Else
  81.                         suma = suma + DataGridView1.Rows(i).Cells(x).Value
  82.                     End If
  83.                     Me.DataGridView1.Item(16, i).Value = suma
  84.                 Next
  85.                 suma = 0
  86.             Next
  87.  
  88.             pb.Value = 0
  89.             pb.Visible = False
  90.             '--------------------------------------------------------------------
  91.            '--------------------------------------------------------------------
  #4 (permalink)  
Antiguo 14/02/2011, 09:47
 
Fecha de Ingreso: enero-2011
Ubicación: La Serena
Mensajes: 28
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: como pasar todo el contenido datagreedview a una variable

es muy larga ya que no se como llenar el datagreedview con una sola consulta queria hacerlo asi
Código vb:
Ver original
  1. Dim mosene As New OleDb.OleDbDataAdapter("select DISTINCT (d.CodigoPrestacion) as Código, p.NOMBRE_PRESTACION as Prestación, p.REM_PRESTACION as Rem, p.SECCION as Sección, d.Col01 as Enero from DatosSerieA d, PRESTACIONES p where d.CodigoPrestacion=p.CODIGO_PRESTACION and d.IdEstablecimiento='" & Me.Label7.Text & "' and d.Mes=1 and Ano=" & Me.ComboBox2.Text & "", conectar)
  2.             Dim datos As New DataSet
  3.             mosene.Fill(datos)
  4.             Me.DataGridView1.DataSource = datos.Tables(0)
pero no se como agrupar todos los meses en esa consulta :(
  #5 (permalink)  
Antiguo 14/02/2011, 09:50
 
Fecha de Ingreso: febrero-2010
Ubicación: México
Mensajes: 738
Antigüedad: 14 años, 2 meses
Puntos: 37
Respuesta: como pasar todo el contenido datagreedview a una variable

Te pregunto esto porque aqui el la información sigue guardada:
Código vb:
Ver original
  1. Dim datos As New DataSet
  2.  
  3. [B]mosene.Fill(datos)[/B]

Las siguientes columnas que aparecen se las agregas a las que te creo la consulta?
Agregas información adicional a la que te regresa la consulta?
__________________
http://ka0stj.wordpress.com/
  #6 (permalink)  
Antiguo 14/02/2011, 10:00
 
Fecha de Ingreso: enero-2011
Ubicación: La Serena
Mensajes: 28
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: como pasar todo el contenido datagreedview a una variable

agrego las otras columnas porque necesito los campos de la primera consulta para comparar y asi poder entregar un reporte bueno, de esta manera me aseguro q los datos sean los q corresponden.
esto ya que estoy trabajando con bd access y no confio mucho en esta bd asi que tengo que hacer todas las consultas lo mas detallado posible
  #7 (permalink)  
Antiguo 14/02/2011, 10:20
 
Fecha de Ingreso: febrero-2010
Ubicación: México
Mensajes: 738
Antigüedad: 14 años, 2 meses
Puntos: 37
Respuesta: como pasar todo el contenido datagreedview a una variable

Checa estos enlaces:

http://www.forosdelweb.com/f69/recor...-tabla-588034/
http://www.onglasses.net/Default.aspx?id=1199
__________________
http://ka0stj.wordpress.com/
  #8 (permalink)  
Antiguo 14/02/2011, 10:25
 
Fecha de Ingreso: febrero-2010
Ubicación: México
Mensajes: 738
Antigüedad: 14 años, 2 meses
Puntos: 37
Respuesta: como pasar todo el contenido datagreedview a una variable

Checa el siguiente también:

http://social.msdn.microsoft.com/For...9-f456dd766055
__________________
http://ka0stj.wordpress.com/

Etiquetas: contenido, pasar, todo, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:22.