Essentially I know how to do it for one row, however I can't get it to do it for the next row if I input data there.

Attached below is what the form looks like:

Name:  Untitled-1.jpg
Views: 619
Size:  35.9 KB


So the value is added in the datagridview from the form, the update button is clicked and the inserts them into the table itself in the database, the datagridview is used as the input method.

My code is outlined below:

Dim con As New SqlConnection(My.Settings.DiabetesServerConStr)
Dim insertNewValues As New SqlCommand()
insertNewValues.Connection = con
With insertNewValues.Parameters
.Add("@UserID", SqlDbType.Int).Value = BloodSugarDiary.Rows(0).Cells(0).Value
.Add("@Date", SqlDbType.Date).Value = Date.Today()
.Add("@BreakfastLevels", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(2).Value
.Add("@LunchLevels", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(3).Value
.Add("@DinnerLevels", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(4).Value
.Add("@BedLevels", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(5).Value
.Add("@BreakfastCarbs", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(6).Value
.Add("@LunchCarbs", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(7).Value
.Add("@DinnerCarbs", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(8).Value
.Add("@BreakfastInsulin", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(9).Value
.Add("@LunchInsulin", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(10).Value
.Add("@DinnerInsulin", SqlDbType.Float).Value = BloodSugarDiary.Rows(0).Cells(11).Value
End With
Dim parcomstr As String = "INSERT INTO BloodSugarDiary (UserID, Date, BreakfastLevels, LunchLevels, DinnerLevels, BedLevels, BreakfastCarbs, LunchCarbs, DinnerCarbs, BreakfastInsulin, LunchInsulin, DinnerInsulin)VALUES (@UserID, @Date, @BreakfastLevels, @LunchLevels, @DinnerLevels, @BedLevels, @BreakfastCarbs, @LunchCarbs, @DinnerCarbs, @BreakfastInsulin, @LunchInsulin, @DinnerInsulin)"
insertNewValues.CommandText = parcomstr
Try
con.Open()
insertNewValues.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Dispose()
End Sub

Whilst I can get the first row to save into the database, how can I do it for multiple rows?