Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/02/2011, 11:38
guillebomtrasmiti
 
Fecha de Ingreso: noviembre-2010
Ubicación: madrid
Mensajes: 478
Antigüedad: 14 años, 3 meses
Puntos: 5
Pregunta Seleccion de una base de datos

Hola, tengo una base de datos en SQL que contiene productos, en un formulario se cargan los botones con los nombres de los productos de la base de datos, ahora he creado un datagridview dónde quiero que al pulsar un botón del formluario se carguen en 3 campos en el datagridview...¿me agudais=¿
el código;
Código vb:
Ver original
  1. Private Sub renovarBotones()
  2.         ''Aqui verifico si se presiono para eliminar los
  3.        ''botones creados anteriormente y no se esten
  4.        ''amontonando con los de la otra consulta
  5.        If accion = 1 Then
  6.             ' Recorremos la colección de controles del formulario
  7.            For Each ctrl As Control In Me.Controls
  8.                 ' Si el tipo de control es un Button
  9.                If TypeOf ctrl Is Button Then
  10.                     ' Si se llama "x"
  11.                    If ctrl.Name = "x" Then
  12.                         ' Lo eliminamos de la colección
  13.                        Me.Controls.Remove(ctrl)
  14.                         'AQUI VUELVO A LLAMAR AL METODO ,SI ELIMINO UN BOTON QUE HAGA
  15.                        'OTRA REVISION SINO QUE NO HAGA NADA PORQUE YA NO HAY
  16.                        renovarBotones()
  17.                     End If
  18.                 End If
  19.             Next
  20.             'Limpio la tabla productos para que no se incremente
  21.            undataset.Tables("productos").Clear()
  22.         End If
  23.     End Sub
  24.     Public Sub cargar_formulario_Productos(ByVal fam As String)
  25.         conexion.ConnectionString = "Data Source=.\SQLEXPRESS11;AttachDbFilename=C:\VISUAL\TpvVigoSe\TpvVigo\Tpv.mdf;" & _
  26.         "Integrated Security=True;" & _
  27.         "Connect Timeout=30;" & _
  28.         "User Instance=True"
  29.         'Creo las variables que definen el area de botones por fila
  30.        Dim bxf, contador As Integer
  31.         'Creo la variables que contendran las dimensiones de los botones
  32.        Dim altoBoton, anchoBoton As Integer
  33.         'Creo las variables de los puntos en los cuales empiezo a pintar los botones
  34.        Dim x, y As Integer
  35.         '-------------------------------------------------------------------------------------------
  36.        bxf = 9 'Por ejemplo defino 9 botones por fila
  37.        contador = 0
  38.         anchoBoton = 54
  39.         altoBoton = 87
  40.         x = 10
  41.         y = 320
  42.         'AQUI HAGO LA RECURSIVIDAD PARA ELIMINAR BOTONES
  43.        renovarBotones()
  44.         ''--------------------------------------------------------------------------------------------------------
  45.        Dim conlumna As New DataColumn
  46.         conlumna.ColumnName.Contains("Producto")
  47.  
  48.         cmd.Connection = conexion
  49.         cmd.CommandText = "select Producto from Productos where NFamilia = " & fam & " ORDER BY Orden ASC"
  50.         adapta.SelectCommand = cmd
  51.         adapta.Fill(undataset, "Productos")
  52.         For i As Integer = 0 To undataset.Tables("Productos").Rows.Count - 1
  53.             'Si alcanzo el maximo de columnas de la fila a pintar
  54.            If contador = bxf Then
  55.                 'seteo el valor del contador
  56.                contador = 0
  57.                 'doy la coordenada para que inicie otra fila para crear botones
  58.                y = y + anchoBoton
  59.                 x = 10
  60.             End If
  61.             Dim nuevobotonProd As New Button
  62.             nuevobotonProd.BackColor = Color.Khaki
  63.             nuevobotonProd.Name = "x"
  64.             nuevobotonProd.Location = New Point(x, y)
  65.             nuevobotonProd.Size = New Size(altoBoton, anchoBoton)
  66.             nuevobotonProd.Text = undataset.Tables("Productos").Rows(i).Item(0).ToString()
  67.             Me.Controls.Add(nuevobotonProd)
  68.             'Aumento contador de columnas
  69.            contador = contador + 1
  70.             'aumento la coordenada para crear otro boton en la siguiente columna
  71.            x = x + altoBoton
  72.         Next
  73.     End Sub
  74. Public Sub insertaparrillaventa()
  75.         conexion.ConnectionString = "Data Source=.\SQLEXPRESS11;AttachDbFilename=C:\VISUAL\TpvVigoSe\TpvVigo\Tpv.mdf;" & _
  76.        "Integrated Security=True;" & _
  77.        "Connect Timeout=30;" & _
  78.        "User Instance=True"
  79.  
  80.         cmd.CommandText = "Insert Into GuardarVentas(NombreProducto,Cantidad,Euros) Select Productos.Producto, Productos.Consumo, Productos.Tarifa1 from Productos"
  81.  
  82.         adapta.SelectCommand = cmd
  83.         adapta.Fill(undataset, "Productos,GuardarVentas")