I'm not sure what you are doing wrong. But try this code. If an error occur it ensure rollback of the database. Note that I assume that the datatype of the net_fee and enrollment columns are Integer.
Using connection As SqlConnection = New SqlConnection("TODO: Set connection string.")
Dim table As DataTable = New DataTable("stu_dtl")
Dim [error] As Exception = Nothing
Using command As SqlCommand = connection.CreateCommand()
command.CommandText = "SELECT [enrollment], [total_fee], [discount], [net_fee] FROM [stu_dtl];"
Using adapter As New SqlDataAdapter(command)
adapter.Fill(table)
End Using
End Using
Using transaction As SqlTransaction = connection.BeginTransaction()
Try
Dim net_fee As Integer = 0
Dim enrollment As Integer = 0
For Each row As DataRow In table.Rows
net_fee = (CInt(row.Item("total_fee")) - CInt(row.Item("discount")))
enrollment = CInt(row.Item("enrollment"))
Using command As SqlCommand = connection.CreateCommand()
command.CommandText = "UPDATE [stu_dtl] SET [net_fee] = @net_fee WHERE [enrollment] = @enrollment;"
command.Parameters.AddWithValue("@net_fee", net_fee)
command.Parameters.AddWithValue("@enrollment", enrollment)
command.ExecuteNonQuery()
End Using
Next
transaction.Commit()
Catch ex As Exception
[error] = ex
transaction.Rollback()
End Try
End Using
If (Not table Is Nothing) Then
table.Dispose()
table = Nothing
End If
If (Not [error] Is Nothing) Then
Throw [error]
End If
End Using
Edit
Come to think of it, you might want to change the net_fee column to a computed column. The formula would simply be ([total_fee] - [discount]).