Update Not Working for asp:DataGrid (VB2003 Standard)

Discussion in 'ASP .Net Datagrid Control' started by Schultz, May 8, 2005.

  1. Schultz

    Schultz Guest

    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
     
    Schultz, May 8, 2005
    #1
    1. Advertising

  2. Schultz

    Elton W Guest

    Remove BindDataGrid() from your code.

    HTH

    Elton Wang


    >-----Original Message-----
    >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
    >
    >.
    >
     
    Elton W, May 8, 2005
    #2
    1. Advertising

  3. Schultz, here's a guess... try clearing the Parameters collection in the
    loop. That is, in the loop add:

    cmdUp.Parameters.Clear()

    Also, I have an article on creating a fully editable DataGrid you might
    find helpful:
    http://aspnet.4guysfromrolla.com/articles/121504-1.aspx

    hth! :)



    Schultz wrote:
    > 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
    >
     
    Scott Mitchell [MVP], May 8, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schultz
    Replies:
    1
    Views:
    523
    David Lloyd
    May 8, 2005
  2. S.Tedeschi
    Replies:
    0
    Views:
    323
    S.Tedeschi
    Jun 15, 2007
  3. S.Tedeschi
    Replies:
    0
    Views:
    304
    S.Tedeschi
    Jun 15, 2007
  4. Andreas Klemt
    Replies:
    0
    Views:
    313
    Andreas Klemt
    Oct 8, 2003
  5. datagrid update/cancel command not working

    , Sep 15, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    728
Loading...

Share This Page