Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/08/2012, 06:46
nelsonpk
 
Fecha de Ingreso: mayo-2012
Ubicación: Argentina, Buenos Aires
Mensajes: 28
Antigüedad: 12 años
Puntos: 1
Respuesta: Variables 'single' y campos 'float' de mysql [VB]

Para guardar los datos uso el conector .NET que dan en la página oficial de mysql, creo la conexión y con esta función que cree guardo los datos:

Código PHP:
Public Function insert_into(ByVal table As StringByVal args As StringByVal values As String)

        
conexion.Open()

        
Dim sqlcommand As String "INSERT INTO " table " ( " args " ) VALUES ( " values " )"
        
Dim command As MySqlCommand = New MySqlCommand(sqlcommandconexion)

        Try

            
command.ExecuteNonQuery()

        Catch 
mi As MySqlException

            MsgBox
("Error en la instrucción MySQL: " mi.MessagevbCritical)
            
End

        End 
Try

        
conexion.Close()

        Return 
True

    End 
Function 
Esta es la tabla...
Código:
CREATE TABLE `ventas` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `userid` int(11) unsigned NOT NULL,
  `cod` varchar(64) NOT NULL,
  `precio` float NOT NULL,
  `hora` int(11) unsigned NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Y así guardo especificamente en esa tabla...

Código PHP:
Private Function ventas_actual_a_general()

        
Form1.conexion.Open()

        
Dim sqlcommand As String "SELECT * FROM venta_actual"
        
Dim command As MySqlCommand = New MySqlCommand(sqlcommandForm1.conexion)
        
Dim reader As MySqlDataReader command.ExecuteReader()

        
Dim result As Boolean

        
Try

            If 
reader.HasRows False Then

                MsgBox
("Error: Se ha cerrado una venta que no tiene productos."vbCritical)

                
reader.Close()
                
Form1.conexion.Close()

                
result False

            
Else

                
Dim i As Integer
                i 
0

                
While (reader.Read())

                    
array_cod(i) = reader!cod
                    array_precio
(i) = Convert.ToSingle(reader!precio)

                    
1

                End 
While

                
reader.Close()

                
Form1.conexion.Close()

                For 
As Integer 0 To array_cod.Length 1

                    
If array_cod(x) <> "" And array_cod(x) <> " " Then

                        Form1
.insert_into("ventas""userid, cod, precio, hora""'" userid "', '" _
                                          array_cod
(x) & "', '" array_precio(x) & _
                                          
"', '" Form1.TimeToUnix(Now) & "'")

                    
End If

                
Next

                Call borrar_venta_actual
()

                For 
0 To 255

                    array_cod
(x) = Nothing
                    array_precio
(x) = Nothing

                Next

                result 
True

            End 
If

        Catch 
mi As MySqlException

            MsgBox
("Error en la instrucción MySQL: " mi.MessagevbCritical)
            
End

        End 
Try

        Return 
result

    End 
Function 
PD: Provaré lo del redondeo.
Edit: Lo del redondeo funcionó, gracias !

Última edición por nelsonpk; 17/08/2012 a las 07:01