Imports
System.Data.SqlClient
Imports
System.Text
Namespace
RMCWebSite
Public Class handbook
Inherits System.Web.UI.Page
Protected WithEvents txtID As System.Web.UI.WebControls.TextBox
Protected WithEvents txtSchoolYear System.Web.UI.WebControls.TextBox
Protected WithEvents txtTeamName As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button3 As System.Web.UI.WebControls.Button
Protected WithEvents Button4 As System.Web.UI.WebControls.Button
Protected WithEvents Button5 As System.Web.UI.WebControls.Button
Dim mySqlDataAdapter As SqlDataAdapter
Dim myDataSet As Data.DataSet = New Data.DataSet()
Dim myDataTable As Data.DataTable = New Data.DataTable()
Dim myConnection As SqlConnection
Dim myCommand As SqlCommandBuilder
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myConnection =
New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("rmcws"))
Try
mySqlDataAdapter =
New SqlDataAdapter("SELECT * FROM SportsTeams", myConnection)
Catch
Console.WriteLine(
"Error Opening {0}", myConnection.DataSource)
End Try
myCommand =
New SqlCommandBuilder(mySqlDataAdapter)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'submit button
myConnection.Open()
mySqlDataAdapter.Fill(myDataSet,
"SportsTeams")
myConnection.Close()
myDataTable = myDataSet.Tables(
"SportsTeams")
Dim rowSportsTeams As Data.DataRow = myDataTable.NewRow()
rowSportsTeams(
"ID") = txtID.Text
rowSportsTeams(
"SchoolYear") = txtSchoolYear.Text
rowSportsTeams(
"TeamName") = txtTeamName.Text
myDataTable.Rows.Add(rowSportsTeams)
mySqlDataAdapter.Update(myDataSet,
"SportsTeams")
myDataSet.Tables(
"SportsTeams").AcceptChanges()
Refresh()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'add new button
ClearScreen()
myConnection.Open()
mySqlDataAdapter.Fill(myDataSet,
"SportsTeams")
myConnection.Close()
myDataTable = myDataSet.Tables(
"SportsTeams")
Dim rowSportsTeams As Data.DataRow = myDataTable.NewRow()
rowSportsTeams(
"ID") = txtID.Text
rowSportsTeams(
"SchoolYear") = txtSchoolYear.Text
rowSportsTeams(
"TeamName") = txtTeamName.Text
Dim newDataSet As Data.DataSet
newDataSet = myDataSet.GetChanges()
mySqlDataAdapter.Update(newDataSet,
"SportsTeams")
myDataSet.Tables(
"SportsTeams").AcceptChanges()
Refresh()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'delete button
myConnection.Open()
mySqlDataAdapter.Fill(myDataSet,
"SportsTeams")
myConnection.Close()
myDataTable = myDataSet.Tables(
"SportsTeams")
myDataTable.Rows(0).Delete()
mySqlDataAdapter.Update(myDataSet,
"SportsTeams")
myDataSet.Tables(
"SportsTeams").AcceptChanges()
Refresh()
End Sub
Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.click 'refresh
RefreshL()
End Sub
Private Sub ClearScreen()
txtID.Text =
""
txtSchoolYear.Text =
""
txtTeamName.Text =
""
End Sub
Private Sub Refresh()
myDataSet =
New Data.DataSet()
myDataTable =
New Data.DataTable()
myConnection.Open()
mySqlDataAdapter.Fill(myDataSet,
"SportsTeams")
myConnection.Close()
myDataTable = myDataSet.Tables(
"SportsTeams")
Dim rowSportsTeams As Data.DataRow = myDataTable.Rows(5)
txtID.Text = rowSportsTeams(
"ID")
txtSchoolYear.Text = rowSportsTeams(
"SchoolYear")
txtTeamName.Text = rowSportsTeams(
"TeamName")
End Sub
End Class
End
Namespace