1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Editing Datagrid

Discussion in 'C#' started by twhitma1, Apr 26, 2007.

  1. #1
    Hi Everyone,
    I have brought in a table from SQL Server into ASP.NET through Datagrid and have turned all fields into textboxes so the user can edit any textbox and click save once. However when the save button is clicked then all textboxes are changed to the value which is in the last row. Here is the code for my save button:

    Private Sub doSave(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim myCommand As SqlCommand
    Dim dstCopy As New DataSet
    Dim strQuery As String

    objConnection = New SqlConnection("server=SQLSERVER;database=upsizedCandidate;Integrated Security=True;")
    objConnection.Open()

    Dim dgItem As DataGridItem
    For Each dgItem In myInfo.Items
    Dim txtNewColumn1 As TextBox = CType(dgItem.Cells(0).FindControl("txtNewCol1"), TextBox)

    Dim txtNewColumn2 As TextBox = CType(dgItem.Cells(1).FindControl("txtNewCol2"), TextBox)

    strQuery = String.Format("update ToddsTable3 set NewCol1= '" + txtNewColumn1.Text + "',NewCol2='" + txtNewColumn2.Text + "'")
    SEMrush
    myCommand = New SqlCommand(strQuery, objConnection)
    myCommand.ExecuteNonQuery()

    Next

    DataBind()
    myInfo.DataBind()
    objConnection.Close()
    myInfo.EditItemIndex = -1


    BindGrid()
    End Sub

    I have no idea what could be wrong and this has been driving me crazy. could anyone please help me? Thanks in advance
     
    twhitma1, Apr 26, 2007 IP
    SEMrush
  2. twhitma1

    twhitma1 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I needed a where statement.....slow today
     
    twhitma1, Apr 26, 2007 IP
  3. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,607
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Glad you got it figured out :)
     
    ccoonen, Apr 26, 2007 IP