D
Derek
I am using a code snippet from
http://www.dotnetjohn.com/articles/articleid83.aspx
to see if i can use it to update data. Here is the
problem/error i am getting.
System.IndexOutOfRangeException: There is no row at
position 0.
Any help would be greatly appreciated. Here is the code
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
binddata()
Else
ReverseBind()
End If
End Sub
Sub binddata()
SqlSelectCommand1.Parameters("@missionid").Value
= 21905
SqlSelectCommand1.Parameters("@Ssn").Value = "%"
SqlDataAdapter1.Fill(Dataset11)
DataGrid1.DataBind()
_LastEditedPage = DataGrid1.CurrentPageIndex
End Sub
Public Sub ReverseBind()
Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_getCrewAssignedSortRow
For Each gridrow In DataGrid1.Items
Next
datarow = Dataset11.og_getCrewAssignedSort
(gridrow.DataSetIndex)
datarow.crewcode() = CType(gridrow.FindControl
("txtCode"), TextBox).Text
datarow.crewqual() = CType(gridrow.FindControl
("txtcrewQual"), TextBox).Text
datarow.crewduty() = CType(gridrow.FindControl
("txtcrewDuty"), TextBox).Text
datarow.persontype() = CType(gridrow.FindControl
("txtFunded"), TextBox).Text
datarow.crewSort() = CType(gridrow.FindControl
("txtsort"), TextBox).Text
Dataset11.og_getCrewAssignedSort
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray
End Sub
Protected Overrides Sub LoadViewState(ByVal
savedstate As Object)
MyBase.LoadViewState(savedstate)
If (Not Me.ViewState("Data") Is Nothing) Then
Dataset11 = CType(Me.ViewState("Data"),
Dataset1)
End If
If (Not Me.ViewState("LastEditedPage") Is
Nothing) Then
_LastEditedPage = CType(Me.ViewState
("LastEditedPage"), Integer)
End If
End Sub
Protected Overrides Function saveViewState() As Object
Me.ViewState("Data") = Dataset11
Me.ViewState("LastEditedPage") = _LastEditedPage
Return (MyBase.SaveViewState())
End Function
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim datarow As
Dataset1.og_getCrewAssignedSortRow
datarow = CType(CType(e.Item.DataItem,
DataRowView).Row, Dataset1.og_getCrewAssignedSortRow)
CType(e.Item.FindControl("txtcode"),
TextBox).Text = datarow.crewcode
CType(e.Item.FindControl("txtcrewQual"),
TextBox).Text = datarow.crewqual
CType(e.Item.FindControl("txtcrewDuty"),
TextBox).Text = datarow.crewduty
CType(e.Item.FindControl("txtFunded"),
TextBox).Text = datarow.persontype
CType(e.Item.FindControl("txtSort"),
TextBox).Text = datarow.crewSort
End If
End Sub
Private Sub Save_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Save.Click
DataGrid1.AllowPaging = False
DataGrid1.DataSource =
_Dataset11.og_getCrewAssignedSort
ReverseBind()
updateData()
End Sub
Sub updateData()
Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_getCrewAssignedSortRow
Dim txtcq As TextBox
Dim strcq As String
Dim txtcd As TextBox
Dim strcd As String
Dim txtptype As TextBox
Dim strptype As String
Dim txtccode As TextBox
Dim strccode As String
Dim txtcsort As TextBox
Dim intcsort As Integer
For Each gridrow In DataGrid1.Items
datarow = _dataset.og_getCrewAssignedSort
(gridrow.DataSetIndex)
txtcq = gridrow.FindControl("txtcrewqual")
strcq = txtcq.Text
txtcd = gridrow.FindControl("txtcrewduty")
strcd = txtcd.Text
txtptype = gridrow.FindControl("txtFunded")
strptype = txtptype.Text
txtccode = gridrow.FindControl("txtcode")
strccode = txtccode.Text
txtcsort = gridrow.FindControl("txtsort")
intcsort = CType(txtcsort.Text, Integer)
SqlUpdateCommand1.Parameters("@cq").Value =
strcq
SqlUpdateCommand1.Parameters("@cd").Value =
strcd
SqlUpdateCommand1.Parameters("@ptype").Value
= strptype
SqlUpdateCommand1.Parameters("@ccode").Value
= strccode
SqlUpdateCommand1.Parameters("@csort").Value
= intcsort
SqlUpdateCommand1.Parameters("@sid").Value =
1593
SqlConnection1.Open()
SqlUpdateCommand1.ExecuteNonQuery()
SqlConnection1.Close()
Next
End Sub
End Class
http://www.dotnetjohn.com/articles/articleid83.aspx
to see if i can use it to update data. Here is the
problem/error i am getting.
System.IndexOutOfRangeException: There is no row at
position 0.
Any help would be greatly appreciated. Here is the code
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
binddata()
Else
ReverseBind()
End If
End Sub
Sub binddata()
SqlSelectCommand1.Parameters("@missionid").Value
= 21905
SqlSelectCommand1.Parameters("@Ssn").Value = "%"
SqlDataAdapter1.Fill(Dataset11)
DataGrid1.DataBind()
_LastEditedPage = DataGrid1.CurrentPageIndex
End Sub
Public Sub ReverseBind()
Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_getCrewAssignedSortRow
For Each gridrow In DataGrid1.Items
Next
datarow = Dataset11.og_getCrewAssignedSort
(gridrow.DataSetIndex)
datarow.crewcode() = CType(gridrow.FindControl
("txtCode"), TextBox).Text
datarow.crewqual() = CType(gridrow.FindControl
("txtcrewQual"), TextBox).Text
datarow.crewduty() = CType(gridrow.FindControl
("txtcrewDuty"), TextBox).Text
datarow.persontype() = CType(gridrow.FindControl
("txtFunded"), TextBox).Text
datarow.crewSort() = CType(gridrow.FindControl
("txtsort"), TextBox).Text
Dataset11.og_getCrewAssignedSort
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray
End Sub
Protected Overrides Sub LoadViewState(ByVal
savedstate As Object)
MyBase.LoadViewState(savedstate)
If (Not Me.ViewState("Data") Is Nothing) Then
Dataset11 = CType(Me.ViewState("Data"),
Dataset1)
End If
If (Not Me.ViewState("LastEditedPage") Is
Nothing) Then
_LastEditedPage = CType(Me.ViewState
("LastEditedPage"), Integer)
End If
End Sub
Protected Overrides Function saveViewState() As Object
Me.ViewState("Data") = Dataset11
Me.ViewState("LastEditedPage") = _LastEditedPage
Return (MyBase.SaveViewState())
End Function
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim datarow As
Dataset1.og_getCrewAssignedSortRow
datarow = CType(CType(e.Item.DataItem,
DataRowView).Row, Dataset1.og_getCrewAssignedSortRow)
CType(e.Item.FindControl("txtcode"),
TextBox).Text = datarow.crewcode
CType(e.Item.FindControl("txtcrewQual"),
TextBox).Text = datarow.crewqual
CType(e.Item.FindControl("txtcrewDuty"),
TextBox).Text = datarow.crewduty
CType(e.Item.FindControl("txtFunded"),
TextBox).Text = datarow.persontype
CType(e.Item.FindControl("txtSort"),
TextBox).Text = datarow.crewSort
End If
End Sub
Private Sub Save_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Save.Click
DataGrid1.AllowPaging = False
DataGrid1.DataSource =
_Dataset11.og_getCrewAssignedSort
ReverseBind()
updateData()
End Sub
Sub updateData()
Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_getCrewAssignedSortRow
Dim txtcq As TextBox
Dim strcq As String
Dim txtcd As TextBox
Dim strcd As String
Dim txtptype As TextBox
Dim strptype As String
Dim txtccode As TextBox
Dim strccode As String
Dim txtcsort As TextBox
Dim intcsort As Integer
For Each gridrow In DataGrid1.Items
datarow = _dataset.og_getCrewAssignedSort
(gridrow.DataSetIndex)
txtcq = gridrow.FindControl("txtcrewqual")
strcq = txtcq.Text
txtcd = gridrow.FindControl("txtcrewduty")
strcd = txtcd.Text
txtptype = gridrow.FindControl("txtFunded")
strptype = txtptype.Text
txtccode = gridrow.FindControl("txtcode")
strccode = txtccode.Text
txtcsort = gridrow.FindControl("txtsort")
intcsort = CType(txtcsort.Text, Integer)
SqlUpdateCommand1.Parameters("@cq").Value =
strcq
SqlUpdateCommand1.Parameters("@cd").Value =
strcd
SqlUpdateCommand1.Parameters("@ptype").Value
= strptype
SqlUpdateCommand1.Parameters("@ccode").Value
= strccode
SqlUpdateCommand1.Parameters("@csort").Value
= intcsort
SqlUpdateCommand1.Parameters("@sid").Value =
1593
SqlConnection1.Open()
SqlUpdateCommand1.ExecuteNonQuery()
SqlConnection1.Close()
Next
End Sub
End Class