4つのテキストボックスが入力されている場合は、データベースの計算と更新を行います。4つのテキストボックスが埋め込まれている場合の計算と更新VB.net
1または2または3が満たされていると計算されず、データベースに更新されます。
ここは私のコードです。
Dim constring As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=|DataDirectory|\SLACdb.mdb;"
Dim con As OleDbConnection = New OleDbConnection(constring)
Dim cmd As OleDbCommand
Dim dt As DataTable = New DataTable()
Dim prelim, midterm, prefinal, final, ave, eq As String
prelim = txtboxprelim.Text
midterm = txtboxmidterm.Text
prefinal = txtboxsemi.Text
final = txtboxfinals.Text
ave = txtboxave.Text
eq = txtboxequivalent.Text
Dim sql As String = "UPDATE StudentLoad SET prelim = ?, midterm = ?, semifinals = ?, finals = ?" & _
" WHERE name = '" & txtboxname.Text & "' "
If prelim = "" Or midterm = "" Or prefinal = "" Or final = "" Then
cmd = New OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("@p1", prelim)
cmd.Parameters.AddWithValue("@p2", midterm)
cmd.Parameters.AddWithValue("@p3", prefinal)
cmd.Parameters.AddWithValue("@p4", final)
Try
con.Open()
If (cmd.ExecuteNonQuery > 0) Then
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Me.StudentRemarksTableAdapter.Fill(Me.SLACdbDataSet.StudentRemarks)
Else
txtboxave.Text = (prelim + midterm + prefinal + final)/4
If txtboxave.Text <= 77 Then
txtboxequivalent.Text = 3
ElseIf txtboxave.Text <= 80 Then
txtboxequivalent.Text = 2.75
ElseIf txtboxave.Text <= 83 Then
txtboxequivalent.Text = 2.5
ElseIf txtboxave.Text <= 86 Then
txtboxequivalent.Text = 2.25
ElseIf txtboxave.Text <= 89 Then
txtboxequivalent.Text = 2
ElseIf txtboxave.Text <= 92 Then
txtboxequivalent.Text = 1.75
ElseIf txtboxave.Text <= 95 Then
txtboxequivalent.Text = 1.5
ElseIf txtboxave.Text <= 98 Then
txtboxequivalent.Text = 1.25
ElseIf txtboxave.Text <= 100 Then
txtboxequivalent.Text = 1
Else
txtboxequivalent.Text = 5
End If
Dim constring1 As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=|DataDirectory|\SLACdb.mdb;"
Dim con1 As OleDbConnection = New OleDbConnection(constring1)
Dim cmd1 As OleDbCommand
Dim dt1 As DataTable = New DataTable()
Dim sql1 As String = "UPDATE StudentLoad SET prelim = ?, midterm = ?, semifinals = ?, finals = ?, average = ?, equivalent = ?" & _
" WHERE name = '" & txtboxname.Text & "'"
cmd1 = New OleDbCommand(sql1, con1)
cmd1.Parameters.AddWithValue("@p1", prelim)
cmd1.Parameters.AddWithValue("@p2", midterm)
cmd1.Parameters.AddWithValue("@p3", prefinal)
cmd1.Parameters.AddWithValue("@p4", final)
cmd1.Parameters.AddWithValue("@p5", ave)
cmd1.Parameters.AddWithValue("@p6", eq)
Try
con1.Open()
If (cmd1.ExecuteNonQuery > 0) Then
End If
con1.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Me.StudentRemarksTableAdapter.Fill(Me.SLACdbDataSet.StudentRemarks)
Admin.StudentLoadTableAdapter.Update(SLACdbDataSet.StudentLoad)
このコードでは、4つのテキストボックスがいっぱいになるとデータベースが更新されますが、計算されません。
申し訳ありませんの悪い英語