Imports System.Data
Imports System.Data.SqlClient
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Function call_add()
Dim tam, eng, mat, sci, soc, tot As Decimal
tam = 0
eng = 0
mat = 0
sci = 0
soc = 0
tot = 0
If tamil.Text <> "" Then
tam = Convert.ToDecimal(tamil.Text)
End If
If english.Text <> "" Then
eng = Convert.ToDecimal(english.Text)
End If
If maths.Text <> "" Then
mat = Convert.ToDecimal(maths.Text)
End If
If science.Text <> "" Then
sci = Convert.ToDecimal(science.Text)
End If
If social.Text <> "" Then
soc = Convert.ToDecimal(social.Text)
End If
tot = tam + eng + mat + sci + soc
total.Text = tot.ToString
percentage.Text = total.Text/500 * 100
Return False
End Function
Private Sub total_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles total.TextChanged
call_add()
End Sub
Private Sub percentage_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles percentage.TextChanged
call_add()
End Sub
Private Sub tamil_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tamil.TextChanged
call_add()
End Sub
Private Sub english_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles english.TextChanged
call_add()
End Sub
Private Sub maths_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles maths.TextChanged
call_add()
End Sub
Private Sub science_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles science.TextChanged
call_add()
End Sub
Private Sub social_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles social.TextChanged
call_add()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As SqlConnection
Dim cmd As SqlCommand
'Dim str As String
con = New SqlConnection("server=WHITE-PC\WHITEPC;initial catalog=markreg;Integrated Security=True")
cmd = New SqlCommand
con.Open()
Dim command As New SqlCommand
cmd.Connection = con
command = New SqlCommand("stdregno,stdname,tamil,english,maths,science,social,total,percentage", con)
command.ExecuteNonQuery()
con.Close()
MsgBox("Added Sucessfully", MsgBoxStyle.Information, "Succesfully")
call_clear()
End Sub
Private Function call_clear()
stdregno.Text = ""
stdname.Text = ""
tamil.Text = ""
english.Text = ""
maths.Text = ""
science.Text = ""
social.Text = ""
total.Text = ""
percentage.Text = ""
End Function
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
InputBox("Enter the Regno You want search")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
InputBox("Enter the Regno You want Modify")
End Sub
End Class
歡迎來到SO。請閱讀[如何解答](http://stackoverflow.com/help/how-to-answer),並正確地格式化代碼。 – thewaywewere