I found the solution. The problem was the position of the conditional statement.
What i did was to move the conditional statement up like this:
Public Sub SaveCustomerData()
Dim constr As String = ConfigurationManager.ConnectionStrings("ConnString").ConnectionString
Dim transaction As SqlTransaction
Using con As New SqlConnection(constr)
con.Open()
transaction = con.BeginTransaction()
Try
Dim id As Integer = 0
If Label1.Text <> String.Empty AndAlso Label1.Text IsNot Nothing Then
Using cmd As New SqlCommand("PR", con, transaction)
cmd.Parameters.AddWithValue("@GRNumber", "1233")
cmd.Parameters.Add("@GRID", SqlDbType.BigInt).Direction = ParameterDirection.Output
cmd.CommandType = CommandType.StoredProcedure
cmd.ExecuteNonQuery()
id = Convert.ToInt32(cmd.Parameters("@GRID").Value)
End Using
For Each row As GridViewRow In GView.Rows
Dim ponum As String = DirectCast(row.Cells(1).FindControl("lblPONumber"), Label).Text
Dim partyname As String = DirectCast(row.Cells(2).FindControl("lblPartyName"), Label).Text
Dim itemname As String = DirectCast(row.Cells(3).FindControl("lblItemName"), Label).Text
Dim qty As String = DirectCast(row.Cells(4).FindControl("lblQtyOrdered"), Label).Text
Dim qtydelivered As String = DirectCast(row.Cells(5).FindControl("lblQtyDelivered"), Label).Text
Using cmd As New SqlCommand("PR_Det", con, transaction)
cmd.Parameters.AddWithValue("@GRID", id)
cmd.Parameters.Add("@PONumber", SqlDbType.VarChar).Value = ponum
cmd.Parameters.Add("@PartyName", SqlDbType.VarChar).Value = partyname
cmd.Parameters.Add("@ItemName", SqlDbType.VarChar).Value = itemname
cmd.Parameters.AddWithValue("@QTYOrdered", qty).ToString()
cmd.Parameters.AddWithValue("@QTYReceived", qtydelivered).ToString()
cmd.CommandType = CommandType.StoredProcedure
cmd.ExecuteNonQuery()
End Using
Next
transaction.Commit()
End If
Catch sqlError As SqlException
transaction.Rollback()
Finally
con.Close()
End Try
End Using
End Sub
Note, the value of Label1.Text is gotten from edit/update button. once i click edit button the value of gridview column is passed to Label1.Text. You can see how the edit button works in the following thread:
http://www.aspforums.net/Threads/787552/Fire-Dropdownlist-In-Gridview-Row-When-Edit-Button-Is-Clicked/?p=2
Thank you Shashikant and Dharmendr for your help.