F
Fendi Baba
I wrote a code to loop through an array and only the first item is
updated. I think the sqlcommand is not updated properly in my code but
I am not sure how to go about this.
This is my code:
Partial Class admin_batch
Inherits System.Web.UI.Page
Protected Sub ButtonUpdate_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ButtonUpdate.Click
Dim strconnectionString As String =
WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
Dim con As New SqlConnection(strconnectionString)
Dim s As String
Dim numAff As Integer
Dim value As DateTime
Dim deliveryvalue As String
value = CalIssuedDate.SelectedDate
Deliveryvalue = "True"
Dim words As String = TextBoxUpdate.Text
Dim split As String() = words.Split(Chr(13))
Dim sql5 As String = "Update gown_orders SET
DeliveryStatus=@DeliveryStatus, IssueDate=@DateIssued where
StudentID=@StudentID"
Dim cmd5 As New SqlCommand(sql5, con)
For Each s In split
If s.Trim() <> "" Then
Try
con.Open()
cmd5.Parameters.Clear()
cmd5.Parameters.AddWithValue("@DeliveryStatus",
deliveryvalue)
cmd5.Parameters.AddWithValue("@DateIssued", value)
cmd5.Parameters.AddWithValue("@StudentID",
Trim(s))
numAff = cmd5.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
Exit Try
Finally
Label1.Text = "Successfully Updated"
con.Close()
End Try
End If
Next s
TextBoxUpdate.Text = ""
End Sub
====================================================
Any ideas why the rest of the records are not updatable?
Thanks
updated. I think the sqlcommand is not updated properly in my code but
I am not sure how to go about this.
This is my code:
Partial Class admin_batch
Inherits System.Web.UI.Page
Protected Sub ButtonUpdate_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ButtonUpdate.Click
Dim strconnectionString As String =
WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
Dim con As New SqlConnection(strconnectionString)
Dim s As String
Dim numAff As Integer
Dim value As DateTime
Dim deliveryvalue As String
value = CalIssuedDate.SelectedDate
Deliveryvalue = "True"
Dim words As String = TextBoxUpdate.Text
Dim split As String() = words.Split(Chr(13))
Dim sql5 As String = "Update gown_orders SET
DeliveryStatus=@DeliveryStatus, IssueDate=@DateIssued where
StudentID=@StudentID"
Dim cmd5 As New SqlCommand(sql5, con)
For Each s In split
If s.Trim() <> "" Then
Try
con.Open()
cmd5.Parameters.Clear()
cmd5.Parameters.AddWithValue("@DeliveryStatus",
deliveryvalue)
cmd5.Parameters.AddWithValue("@DateIssued", value)
cmd5.Parameters.AddWithValue("@StudentID",
Trim(s))
numAff = cmd5.ExecuteNonQuery()
Catch ex As Exception
Label1.Text = ex.Message
Exit Try
Finally
Label1.Text = "Successfully Updated"
con.Close()
End Try
End If
Next s
TextBoxUpdate.Text = ""
End Sub
====================================================
Any ideas why the rest of the records are not updatable?
Thanks