CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Feb 2009

    MySql Insert with Parameters (as explicit as posible)

    I used this method in previous versions I'm not sure if it was the old connector i used by then but now it throws "Input string was not in a correct format." at the line "sql.ExecuteNonQuery()"

    Using VB.net 2013 express

    what am i doing wrong or where can i find a good example to insert using parameters but i read somewhere that the method with "addwithvalue" uses implicit conversions and i always target for the best practices i dont want implicit conversions kicking me in the future.

    Thx in advance.

        Public Function AddCliente(ByRef Cedula As String, ByRef Nombres As String, ByRef Apellidos As String, ByRef Telefono As String, ByRef Movil As String, ByRef Direccion As String) As Boolean
            Dim DBCon As MySqlConnection
            DBCon = New MySqlConnection(ConnStr)
                Dim sql As MySqlCommand = New MySqlCommand
                sql.Connection = DBCon
                'Formateando fechas para almacenarlas en la BD
                sql.CommandText = "INSERT INTO Clientes VALUES(@Par1,@Par2,@Par3,@Par4,@Par5,@Par6)"
                Dim Par1 As New MySqlParameter("@Par1", DbType.String)
                Dim Par2 As New MySqlParameter("@Par2", DbType.String)
                Dim Par3 As New MySqlParameter("@Par3", DbType.String)
                Dim Par4 As New MySqlParameter("@Par4", DbType.String)
                Dim Par5 As New MySqlParameter("@Par5", DbType.String)
                Dim Par6 As New MySqlParameter("@Par6", DbType.String)
                Par1.Value = Cedula
                Par2.Value = Nombres
                Par3.Value = Apellidos
                Par4.Value = Telefono
                Par5.Value = Movil
                Par6.Value = Direccion
                sql.CommandType = CommandType.Text
                Return True
            Catch ex As MySqlException
                If (ex.Number) = 1045 Then
                    MsgBox("No se pudo realizar la conexion con el servidor sql. porfavor revisar las configuraciones IP/Puerto del Servidor o de que este se encuentre activo", MsgBoxStyle.Information, "Aviso")
                End If
                Return False
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Information, "AddCliente")
                Return False
            End Try
        End Function

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: MySql Insert with Parameters (as explicit as posible)

    MySQL export:

    INSERTINTO `customers` (`CustomerId`
    \\ 50 more fields
     `CustomerLastLocation`) VALUES 
    (\\ 50 more fields)
    just finished importing 85K rows of 100 fields

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.