Datagrid update

Dstevens66

New member
Joined
Jan 18, 2003
Messages
1
Location
Salem, MA
I bet Im just doing something dumb, but I am using a datagrid to edit and update tables in an MSAccess database. The problem is the update statement is using the value before I type anything new, and so is updating the field to the same value over and over. To test it, I set the cell to be updated to another cell, and the table was updated with that value.

I hope that makes some sense.
Code:
Dim oleCon As OleDbConnection
            oleCon = Session("CNOleDB")
            oleCon.Open()
            Dim sFName As String
            Dim sConID As Integer
            sFName = CType(e.Item.Cells(1).Controls(0), TextBox).Text
            sConID = CType(e.Item.Cells(0).Controls(0), TextBox).Text
            Dim sSqlCmd As OleDbCommand
            sSqlCmd = olecon.CreateCommand
            sSqlCmd.CommandText = "Update tblContacts set FName = [NewFName] where " & _
            "ContactID = [ContID]"
            Dim objParam = New OleDbParameter()
            With objParam
                .parameterName = "[NewFName]"
                .dbtype = DbType.String
                .direction = ParameterDirection.Input
                .value = sFName
            End With
            sSqlCmd.Parameters.Add(objParam)

            Dim objParam1 = New OleDbParameter()
            With objParam1
                .parameterName = "[ContID]"
                .dbtype = DbType.String
                .direction = ParameterDirection.Input
                .value = CType(sConID, Integer)
            End With
            sSqlCmd.Parameters.Add(objParam1)
            Response.Write(sSqlCmd.CommandText)
            sSqlCmd.ExecuteNonQuery()
            oleCon.Close()
            dgContacts.EditItemIndex = -1
            bindit()
 
Last edited by a moderator:
Back
Top