Imports System.Data
Imports System.Data.SqlClient
Private Sub btnCalculateGrade_Click(sender As Object, e As EventArgs) Handles btnCalculateGrade.Click
Call SetData()
End Sub
Private Sub SetData()
Dim cn As String = "Data Source=PC-Name;Initial Catalog=DB_Name;User ID=sa;Password=123"
Using Conn As New SqlConnection(cn)
Conn.Open()
Using tr As SqlTransaction = Conn.BeginTransaction()
Try
Using cmd As SqlCommand = Conn.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = <sql>
UPDATE tblGrade
SET tblGrade.Grade = CASE
WHEN tblGrade.Total >= 90.0
THEN 'A'
WHEN tblGrade.Total >= 80.0
THEN 'B'
WHEN tblGrade.Total >= 70.0
THEN 'C'
WHEN tblGrade.Total >= 60.0
THEN 'D'
WHEN tblGrade.Total >= 50.0
THEN 'E'
ELSE 'F'
END
</sql>.ToString()
cmd.Transaction = tr
cmd.ExecuteNonQuery()
tr.Commit()
End Using
Catch ex As Exception
tr.Rollback()
End Try
End Using
End Using
End Sub