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!:wave:
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
Quote:
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)
Quote:
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
Quote:
.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