Thanks to:
Uma Shankar Patel
Damian S
Solution:
>correction of my sql update statement
>put a for loop to force datagridview index not to negative or more than......
Public Sub updateai()
Dim nsr = DataGridView1.SelectedRows.Count
For i = 0 To (nsr - 1)
Dim updateline As Integer = DataGridView1.SelectedRows(i).Cells(0).Value
Dim updateme As String = "UPDATE ICDTBL SET CreateBy=@CreateBy, StartDate=@StartDate, CloseDate=@CloseDate, StartTime=@StartTime, CloseTime=@CloseTime, Supplier=@Supplier, ActualETA=@ActualETA, OrderNum=@OrderNum, Remark=@Remark, Status=@Status WHERE IDNO = " & updateline & ""
Dim cmd As New SqlCommand(updateme, connection)
If RichTextBox1.Text = "" And TextBox6.Text = "" And TextBox8.Text = "" And TextBox9.Text = "" Then
MsgBox("blank content will not be send out")
Else
Try
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
cmd.Parameters.AddWithValue("@CreateBy", Label10.Text.Trim())
If DateTimePicker1.Value < Date.Today And DateTimePicker2.Value < Date.Today And DateTimePicker1.Value > DateTimePicker2.Value Then
MsgBox("Start Date and Close Date cannot less than today's date AND Start Date cannot more than Close Date")
ElseIf DateTimePicker3.Value < myTime And DateTimePicker4.Value < myTime And DateTimePicker2.Value > DateTimePicker3.Value Then
MsgBox("Start Time and Close Time cannot less than Current Time AND Start Time cannot more than Close Time")
Else
cmd.Parameters.AddWithValue("@StartDate", DateTimePicker1.Value.ToShortDateString())
cmd.Parameters.AddWithValue("@CloseDate", DateTimePicker2.Value.ToShortDateString())
cmd.Parameters.AddWithValue("@StartTime", DateTimePicker3.Value.ToShortTimeString())
cmd.Parameters.AddWithValue("@CloseTime", DateTimePicker4.Value.ToShortTimeString())
End If
cmd.Parameters.AddWithValue("@Supplier", TextBox6.Text.Trim())
cmd.Parameters.AddWithValue("@ActualETA", RichTextBox1.Text.Trim())
cmd.Parameters.AddWithValue("@OrderNum", TextBox8.Text.Trim())
cmd.Parameters.AddWithValue("@Remark", TextBox9.Text.Trim())
If Label12.Text = "" Then
MsgBox("Please specify task status")
Else
cmd.Parameters.AddWithValue("@Status", Label12.Text.Trim())
End If
cmd.ExecuteNonQuery()
MsgBox("Information updated")
connection.Close()
RichTextBox1.Text = ""
TextBox6.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
Label12.Text = ""
loadalll()
Catch ex As SqlException
MsgBox(ex.Message)
End Try
End If
Next