Update Not Working for asp:DataGrid (VB2003 Standard)

S

Schultz

Hi, i am trying to make a fully editable dataGrid and was using the
"Top Ten Questions about the DataGrid Control" article in the MSDN
Library as a guide. The following is my current vb code. I ran the
page, and only the first row updates. Can anyone help with this
problem? Thanks, TS


Public Sub dgUpdate(ByVal s As Object, ByVal e As EventArgs)
Dim i As Integer
Dim dgi As DataGridItem
Dim lblSID As Label
Dim txtC1 As TextBox
Dim txtC2 As TextBox
Dim txtC3 As TextBox
Dim txtC4 As TextBox
Dim txtE1 As TextBox
Dim txtS1 As TextBox
Dim intSID As String 'StudentID
Dim cmdUp As OleDbCommand
Dim strUp


strUp = "Update StudentData Set C1=@C1, C2=@C2, C3=@C3, C4=@C4,

E1=@E1, S1=@S1 Where StudentID=@SID and TchID=@TchID And
CourseID=@CourseID"
cmdUp = New OleDbCommand(strUp, conPI)


Dim totCount As Integer
totCount = dgrdStudents.Items.Count


For i = 0 To totCount - 1
dgi = dgrdStudents.Items(i)
lblSID = CType(dgi.FindControl("lblSID"­), Label)
intSID = CType(lblSID.Text, String)
txtC1 = CType(dgi.FindControl("txtC1")­, TextBox)
txtC2 = CType(dgi.FindControl("txtC2")­, TextBox)
txtC3 = CType(dgi.FindControl("txtC3")­, TextBox)
txtC4 = CType(dgi.FindControl("txtC4")­, TextBox)
txtE1 = CType(dgi.FindControl("txtE1")­, TextBox)
txtS1 = CType(dgi.FindControl("txtS1")­, TextBox)
cmdUp.Parameters.Add("@C1", txtC1.Text)
cmdUp.Parameters.Add("@C2", txtC2.Text)
cmdUp.Parameters.Add("@C3", txtC3.Text)
cmdUp.Parameters.Add("@C4", txtC4.Text)
cmdUp.Parameters.Add("@E1", txtE1.Text)
cmdUp.Parameters.Add("@S1", txtS1.Text)
cmdUp.Parameters.Add("@SID", lblSID.Text)
cmdUp.Parameters.Add("@TchID", varTID)
cmdUp.Parameters.Add("@CourseI­D",
Request.QueryString("CourseID"­))
conPI.Open()
cmdUp.ExecuteNonQuery()
conPI.Close()


Next
BindDataGrid()
End Sub
 
D

David Lloyd

One suggestion I would make is to create your parameters outside of the For
loop. I would then set the Value property of parameter inside the loop.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Hi, i am trying to make a fully editable dataGrid and was using the
"Top Ten Questions about the DataGrid Control" article in the MSDN
Library as a guide. The following is my current vb code. I ran the
page, and only the first row updates. Can anyone help with this
problem? Thanks, TS


Public Sub dgUpdate(ByVal s As Object, ByVal e As EventArgs)
Dim i As Integer
Dim dgi As DataGridItem
Dim lblSID As Label
Dim txtC1 As TextBox
Dim txtC2 As TextBox
Dim txtC3 As TextBox
Dim txtC4 As TextBox
Dim txtE1 As TextBox
Dim txtS1 As TextBox
Dim intSID As String 'StudentID
Dim cmdUp As OleDbCommand
Dim strUp


strUp = "Update StudentData Set C1=@C1, C2=@C2, C3=@C3, C4=@C4,

E1=@E1, S1=@S1 Where StudentID=@SID and TchID=@TchID And
CourseID=@CourseID"
cmdUp = New OleDbCommand(strUp, conPI)


Dim totCount As Integer
totCount = dgrdStudents.Items.Count


For i = 0 To totCount - 1
dgi = dgrdStudents.Items(i)
lblSID = CType(dgi.FindControl("lblSID"­), Label)
intSID = CType(lblSID.Text, String)
txtC1 = CType(dgi.FindControl("txtC1")­, TextBox)
txtC2 = CType(dgi.FindControl("txtC2")­, TextBox)
txtC3 = CType(dgi.FindControl("txtC3")­, TextBox)
txtC4 = CType(dgi.FindControl("txtC4")­, TextBox)
txtE1 = CType(dgi.FindControl("txtE1")­, TextBox)
txtS1 = CType(dgi.FindControl("txtS1")­, TextBox)
cmdUp.Parameters.Add("@C1", txtC1.Text)
cmdUp.Parameters.Add("@C2", txtC2.Text)
cmdUp.Parameters.Add("@C3", txtC3.Text)
cmdUp.Parameters.Add("@C4", txtC4.Text)
cmdUp.Parameters.Add("@E1", txtE1.Text)
cmdUp.Parameters.Add("@S1", txtS1.Text)
cmdUp.Parameters.Add("@Sid", lblSID.Text)
cmdUp.Parameters.Add("@TchID", varTID)
cmdUp.Parameters.Add("@CourseI­D",
Request.QueryString("CourseID"­))
conPI.Open()
cmdUp.ExecuteNonQuery()
conPI.Close()


Next
BindDataGrid()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top