Results 1 to 2 of 2

Thread: save in MySQL all the columns values in listview

  1. #1

    Thread Starter
    Junior Member feroguz's Avatar
    Join Date
    Aug 2013
    Posts
    22

    Question save in MySQL all the columns values in listview

    Hi!

    I have the next development that I want to upload all the columns values of the listview in to MySQL.
    I have the next Code:
    Code:
        'secuencia para guardar en MYSQL
                If sconnection.State = ConnectionState.Closed Then
                    sconnection.ConnectionString = "Data Source=192.168.1.32;Database=time;User ID=MXUZ;Password=Asdas34;"
                    sconnection.Open()
    
                End If
    
                'Dim sqlquery As String = "INSERT INTO registro(user,project,step,date,starttime,endtime,progress,activity,case,line,description) values ('" & user.Text & "','" & ComboBox1.Text & "','" & ComboBox3.Text & "','" & DateTimePicker1.Text & "','" & starttime.Text & "','" & endtime.Text & "','" & TextBox1.Text & "','" & ComboBox5.Text & "','" & TextBox3.Text & "','" & TextBox2.Text & "','" & TextBox2.Text & "')"
                Dim sqlquery As String = "INSERT INTO registro(user,project,step,date,starttime,endtime,progress,activity,line,description,country) values ('" & TimeTracking.Form1.user.Text & "','" & TimeTracking.Form1.TextBox5.Text & "','" & TimeTracking.Form1.ComboBox3.Text & "','" & TimeTracking.Form1.DateTimePicker1.Text & "','" & TimeTracking.Form1.starttime.Text & "','" & TimeTracking.Form1.endtime.Text & "','" & TimeTracking.Form1.TextBox1.Text & "','" & TimeTracking.Form1.ComboBox5.Text & "','" & TimeTracking.Form1.TextBox2.Text & "','" & TimeTracking.Form1.TextBox4.Text & "','" & TimeTracking.Form1.TextBox3.Text & "')"
                Dim sqlcommand As New MySqlCommand
                With sqlcommand
                    .CommandText = sqlquery
                    .Connection = sconnection
                    .ExecuteNonQuery()
    
                End With
    
    
    
    
                Dim sqlid As String = "SELECT registro.id FROM registro"
                Dim id As New MySqlCommand
                With id
                    .CommandText = sqlid
                    .Connection = sconnection
                    .ExecuteNonQuery()
    
                End With
    
    
    
    
            End With
    
            Me.Close()
    This code works but only save the singles values .. What use to indicate that they complete all registration upload it all data column information in to MySQL?

    Best Regards!

  2. #2
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: save in MySQL all the columns values in listview

    first things first
    (!) List view is not the suitable control for this kind of form entry , the best option is datagridview control

    However
    (2) when you need to insert all the columns X rows , you just loop through all rows X columns & build the SQL insert command string and execute command
    Dim sqlcommand As New MySqlCommand
    Loop stat
    With sqlcommand
    .CommandText = sqlquery ' this line also can be out of loop provided if u are using parameters
    .Connection = sconnection ' keep this line out of loop , no need to reassign the connection again & again
    .ExecuteNonQuery()
    .parameters.clear() '' Clear the parametes supplied
    End With
    Loop end
    (3)
    Dim sqlid As String = "SELECT registro.id FROM registro"
    Dim id As New MySqlCommand
    With id
    .CommandText = sqlid
    .Connection = sconnection
    .ExecuteNonQuery()

    End With
    in no 3 you are executing a select query !!!! , read this line carefully
    .ExecuteNonQuery()
    i,e Execute then NonQuery
    means it is not a query , query means you are requesting some information from database , that is the
    general english meaning, but here it is a NonQuery and Executing some command that will not return anything but it will do
    some changes to the records in the database.

    if you need to Query the data
    just use dataadapters or Datareaders
    Last edited by make me rain; Sep 6th, 2013 at 11:05 PM.
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width