Public sKey as string
Public MatchDataID as string
Public dsTeamPlayer As Dataset
Public dsCopy As DataSet
Public tpDataSet as Dataset
Public Sub Page_Load()
If Not Page.IsPostback Then
BindData
End If
End Sub
Public sub BindData()
MatchDataID = Session("MatchDataID")
sKey = Session("TeamID")
Dim oConnect As New OleDbConnection(ConfigurationSettings.AppSettings("connString"))
Dim oDR As OleDbDataAdapter = New OleDbDataAdapter
oDR.SelectCommand = New OleDbCommand("spTeamLineUp" , oConnect)
oDR.SelectCommand.CommandType = CommandType.StoredProcedure
Dim oParam As OleDbParameter = oDR.SelectCommand.Parameters.Add("@ParamID", OleDbType.Integer)
oParam.Value = sKey
oParam.Direction = ParameterDirection.Input
dsTeamPlayer = New Dataset()
oDR.MissingSchemaAction = MissingSchemaAction.AddWithKey
oDR.Fill(dsTeamPlayer, "LastTeamPlayers")
NewDataSet
End Sub
Public Sub NewDataSet
Dim dtTeamPlayers As DataTable = new DataTable("TeamPlayers")
Dim tpDataColumn As DataColumn
Dim tpDataRow As DataRow
tpDataColumn = New DataColumn()
tpDataColumn.DataType = System.Type.GetType("System.Int32")
tpDataColumn.ColumnName = "PNumber"
tpDataColumn.ReadOnly = False
tpDataColumn.Unique = True
tpDataColumn.AutoIncrement = False
dtTeamPlayers.Columns.Add(tpDataColumn)
tpDataColumn = New DataColumn()
tpDataColumn.DataType = System.Type.GetType("System.Int32")
tpDataColumn.ColumnName = "PlayerID"
tpDataColumn.ReadOnly = False
tpDataColumn.Unique = True
tpDataColumn.AutoIncrement = False
dtTeamPlayers.Columns.Add(tpDataColumn)
tpDataColumn = New DataColumn()
tpDataColumn.DataType = System.Type.GetType("System.String")
tpDataColumn.ColumnName = "PlayerName"
tpDataColumn.ReadOnly = False
tpDataColumn.Unique = True
tpDataColumn.AutoIncrement = False
dtTeamPlayers.Columns.Add(tpDataColumn)
tpDataColumn = New DataColumn()
tpDataColumn.DataType = System.Type.GetType("System.String")
tpDataColumn.ColumnName = "TPosition"
tpDataColumn.ReadOnly = False
tpDataColumn.Unique = True
tpDataColumn.AutoIncrement = False
dtTeamPlayers.Columns.Add(tpDataColumn)
tpDataColumn = New DataColumn()
tpDataColumn.DataType = System.Type.GetType("System.Int32")
tpDataColumn.ColumnName = "TPositionID"
tpDataColumn.ReadOnly = False
tpDataColumn.Unique = True
tpDataColumn.AutoIncrement = False
dtTeamPlayers.Columns.Add(tpDataColumn)
tpDataColumn = New DataColumn()
tpDataColumn.DataType = System.Type.GetType("System.Int32")
tpDataColumn.ColumnName = "Goals"
tpDataColumn.ReadOnly = False
tpDataColumn.Unique = False
tpDataColumn.AutoIncrement = False
dtTeamPlayers.Columns.Add(tpDataColumn)
dim tpDataSet As DataSet = New DataSet()
tpDataSet.Tables.Add(dtTeamPlayers)
Dim PrimaryKeyColumns(0) As DataColumn
PrimaryKeyColumns(0)= dtTeamPlayers.Columns("PlayerID")
dtTeamPlayers.PrimaryKey = PrimaryKeyColumns
Dim DataRowCopy as DataRow
for each DataRowCopy in dsTeamPlayer.Tables(0).Rows
tpDataRow = dtTeamPlayers.NewRow()
tpDataRow("PNumber") = DataRowCopy("PNumber")
tpDataRow("PlayerID") = DataRowCopy("PlayerID")
tpDataRow("PlayerName") = DataRowCopy("PlayerName")
tpDataRow("TPosition") = DataRowCopy("TPosition")
tpDataRow("TPositionID") = DataRowCopy("TPositionID")
tpDataRow("Goals") = "0"
dtTeamPlayers.Rows.Add(tpDataRow)
next
dgr1.DataSource = tpDataSet.Tables("TeamPlayers")
dgr1.DataBind()
End sub
Function GetTeamPositions()
Dim oConnect As New OleDbConnection(ConfigurationSettings.AppSettings("connString"))
Dim oCommand As New OleDbCommand("spTeamPositions", oConnect)
oCommand.commandType = CommandType.StoredProcedure
Try
oConnect.Open()
Return oCommand.ExecuteReader(CommandBehavior.CloseConnection)
Catch oErr As Exception
If oConnect.State <> ConnectionState.Closed Then
oConnect.Close()
End If
lblErr.Text = oErr.Message & "<p/>"
End Try
End function
Function GetTeamPlayers()
Dim oConnect As New OleDbConnection(ConfigurationSettings.AppSettings("connString"))
Dim oCommand As New OleDbCommand("spTeamPlayerList", oConnect)
oCommand.commandType = CommandType.StoredProcedure
dim oParam as OleDbParameter
oParam = oCommand.Parameters.Add("@ParamID", _
OleDbType.Integer)
oParam.Direction = ParameterDirection.Input
oParam.Value = sKey
Try
oConnect.Open()
Return oCommand.ExecuteReader(CommandBehavior.CloseConnection)
Catch oErr As Exception
If oConnect.State <> ConnectionState.Closed Then
oConnect.Close()
End If
lblErr.Text = oErr.Message & "<p/>"
End Try
End function
Sub DoItemEdit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
dgr1.EditItemIndex = CInt(E.Item.ItemIndex)
BindData ' [COLOR=Red]this displays the dropdownlists/text boxes of edit mode! But it is refreshing the dataset to original state each time![/COLOR]
End Sub
Sub DoItemUpdate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
tpDataSet.AcceptChanges() '[COLOR=Red]this is where to obj ref error comes in![/COLOR]
dgr1.DataSource = tpDataSet.Tables("TeamPlayers")
dgr1.DataBind()
End Sub
Sub DoItemCancel(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
dgr1.EditItemIndex = -1
BindData
End Sub