Hi,
I have the following code:
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
Using cmd As New SqlCommand("PR", con)
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
If qtydelivered <> String.Empty AndAlso qtydelivered IsNot Nothing AndAlso qtydelivered <> "0" Then
Using cmd As New SqlCommand("PR_Det", con)
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
Else
End If
Next
transaction.Commit()
Catch sqlError As SqlException
transaction.Rollback()
Finally
con.Close()
End Try
End Using
End Sub
I want to check if QTYReceived is = 0. If it is = 0 transaction should not commit. that is to say even though "@GRNumber" has a value it should not commit as long as QTYReceived = 0
I will like to display error or successful message when it is committed or rollback
How do i go about it?
Thanks in advance