Documente Academic
Documente Profesional
Documente Cultură
~~~~~~~
Imports System.Data.OleDb
'TODO: This line of code loads data into the 'StudentDataSet2.Mark' table. You can move, or
remove it, as needed.
Me.MarkTableAdapter.Fill(Me.StudentDataSet2.Mark)
con.Open()
cmd.Connection = con
da.Fill(ds, "Mark")
DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = ds.Tables(0)
End Sub
Private Sub add_Click(ByVal ByVader As System.Object, ByVal e As System.EventArgs) Handles
add.Click
If String.IsNullOrEmpty(TextBox1.Text) Or String.IsNullOrEmpty(TextBox2.Text) Or
String.IsNullOrEmpty(TextBox3.Text) Or String.IsNullOrEmpty(TextBox4.Text) Or
String.IsNullOrEmpty(TextBox5.Text) Or String.IsNullOrEmpty(TextBox6.Text) Or
String.IsNullOrEmpty(TextBox7.Text) Or String.IsNullOrEmpty(TextBox8.Text) Or
String.IsNullOrEmpty(TextBox9.Text) Then
MessageBox.Show("Field is empty")
Else
cmd.CommandText = "INSERT INTO
Mark(ID,Name,Class,Net,OST,COM,TOTAL,AVERAGE,Grade)
VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "','" &
TextBox3.Text &
"','" & TextBox4.Text & "','" & TextBox5.Text & "','" &
TextBox6.Text
& "','" & TextBox7.Text & "','" & TextBox8.Text & "','" &
TextBox9.Text & "')"
cmd.ExecuteNonQuery()
MessageBox.Show("New Record Inserted", "Insert Success", MessageBoxButtons.OK,
MessageBoxIcon.Information)
con.Close()
ds.Clear()
LoadGrid()
End If
End Sub
updatecmd.Enabled = False
delete.Enabled = False
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
MessageBox.Show("Empty Row Selected", "Row Selection", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
add.Enabled = False
updatecmd.Enabled = True
delete.Enabled = True
TextBox1.Text = DataGridView1.Item(0, i).Value
TextBox2.Text = DataGridView1.Item(1, i).Value
TextBox3.Text = DataGridView1.Item(2, i).Value
TextBox4.Text = DataGridView1.Item(3, i).Value
TextBox5.Text = DataGridView1.Item(4, i).Value
TextBox6.Text = DataGridView1.Item(5, i).Value
TextBox7.Text = DataGridView1.Item(6, i).Value
TextBox8.Text = DataGridView1.Item(7, i).Value
TextBox9.Text = DataGridView1.Item(8, i).Value
End If
End Sub
If String.IsNullOrEmpty(TextBox1.Text) Or String.IsNullOrEmpty(TextBox2.Text) Or
String.IsNullOrEmpty(TextBox3.Text) Or String.IsNullOrEmpty(TextBox4.Text) Or
String.IsNullOrEmpty(TextBox5.Text) Or String.IsNullOrEmpty(TextBox6.Text) Or
String.IsNullOrEmpty(TextBox7.Text) Or String.IsNullOrEmpty(TextBox8.Text) Or
String.IsNullOrEmpty(TextBox9.Text) Then
MessageBox.Show("Field is empty")
else
cmd.CommandText = "delete from Mark where Name ='" & TextBox2.Text & "'"
cmd.ExecuteNonQuery()
MessageBox.Show("Record Deleted", "Delete Success", MessageBoxButtons.OK,
MessageBoxIcon.Information)
con.Close()
ds.Clear()
DataGridView1.DataSource = Nothing
LoadGrid()
End If
End Sub
If String.IsNullOrEmpty(TextBox1.Text) Or String.IsNullOrEmpty(TextBox2.Text) Or
String.IsNullOrEmpty(TextBox3.Text) Or String.IsNullOrEmpty(TextBox4.Text) Or
String.IsNullOrEmpty(TextBox5.Text) Or String.IsNullOrEmpty(TextBox6.Text) Or
String.IsNullOrEmpty(TextBox7.Text) Or String.IsNullOrEmpty(TextBox8.Text) Or
String.IsNullOrEmpty(TextBox9.Text) Then
MessageBox.Show("Field is empty")
Else
cmd.CommandText = "UPDATE Mark SET Name='" & TextBox2.Text & "',Class='" &
TextBox3.Text &
"',Net='" & TextBox4.Text & "',OST='" & TextBox5.Text & "',COM='" &
TextBox6.Text & "',Total='" & TextBox7.Text & "',Average='" &
TextBox8.Text &
"',Grade='" & TextBox9.Text & "'WHERE id= " & TextBox1.Text & ";"
cmd.ExecuteNonQuery()
Else
TextBox9.Text = "Re-appear"
End If
Else
TextBox9.Text = "Re-appear"
End If
End Sub
End Class