After updating datagrid, the value of control(0) is same

vickeyurs

Newcomer
Joined
Jun 16, 2003
Messages
8
Location
Dubai
Hi!!

I am trying to update datagrid, there is no error after update, but the datagrid value after the update command is still the same, The problem I am facing is in value of txt1 and txt2

actual value from database:
value for txt1 = "A"
value for txt2 = "3"
value for ID = e.Item.Cells(3).Text ' primary key

followings is the code format:-------------------------------Datagrid_Update

Try
cn.OpenConnection()
Dim updateCommand As SqlCommand

Dim txt1 As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text ' Class
Dim txt2 As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text ' V

updateStrsql = "Update RACE_CLASS SET " & _
"RACE_CLASS.CLASS = '" & txt1 & "', " & _
"RACE_CLASS.V = '" & txt2 & "' " & _
"Where RACE_CLASS.ID = '" & e.Item.Cells(3).Text & "' "

updateCommand = New SqlCommand(updateStrsql, cn.MyConnection)

updateCommand.ExecuteNonQuery()

dtgAdmin.EditItemIndex = -1
CheckTable() ' For databind

Catch ex As Exception
lblStatus.Text = lblStatus.Text & "<br>Exception #" & ex.Message & " <br> " & ex.Source & " <br> " & ex.StackTrace & "<br>"

Finally
cn.CloseConnection()
End Try

'------------------------------------------------------------------
Now the big question is during EDIT when I see the textbox for entering the value, I enter

textbox.text= "AA" in cell 1
textbox.text = "33" in cell 2

well the other cell is ID which is readonly.

Now the problem is after running the update command, the value is same , there is no error on the command.

How can i get the right values on txt1 and txt2 during edit in update method.


Thanks for the help in advance
 
Will add few more code for better analysis

HI!!

Actually I am doing the databind in checktable(method) which inturns calls binddata(method). ( The problem is with txt1 and txt2 it cannot identify the changed value just old values)

I hope you got it.......thanks for the fast response.

check the following code:


Public Sub CheckTable()' -----------------------------------
whichTable = ddTable.SelectedItem.Value
Tcol = 0
Tpk = 0
Headertxt_1 = ""
Headertxt_2 = ""
Headertxt_3 = ""
Headertxt_4 = ""
Header_PK = ""

lblEdit.Text = "Editing for " & ddTable.SelectedItem.Value & " ....[Started]"

If whichTable = "RACE_CLASS" Then
lblEdit.Visible = True


Tcol = 3
Tpk = 3
Headertxt_1 = "CLASS"
Headertxt_2 = "V"
Headertxt_3 = ""
Headertxt_4 = ""
Header_PK = "ID"

BindData(3, 3, Headertxt_1, Headertxt_2, Headertxt_3, Headertxt_4, Header_PK)
End If

End Sub

Public Sub BindData(ByRef Tcol As Int16, ByRef Tpk As Int16, ByRef Headertxt_1 As String, ByRef Headertxt_2 As String, ByVal Headertxt_3 As String, ByRef Headertxt_4 As String, ByRef Header_PK As String)
Try
Dim dgStrSql As String

dgStrSql = "Select * from " & ddTable.SelectedItem.Value.ToString
cn.OpenConnection()

Dim dgDA As New SqlDataAdapter(dgStrSql, cn.MyConnection)
Dim dgDS As New DataSet
Dim colRO As New DataColumn


dgDS.Clear()

dgDA.Fill(dgDS)
dgDS.Tables(0).Columns(Header_PK).ReadOnly = True
dtgAdmin.DataSource = dgDS.Tables(0).DefaultView
dtgAdmin.DataBind()
dtgAdmin.Visible = True

Catch ex As Exception
lblStatus.Text = lblStatus.Text & "<br>Exception #" & ex.Message & " / " & ex.Source & " / " & ex.StackTrace & "<br>"

Finally
cn.CloseConnection()

End Try

End Sub
 
After executing the UPDATE, do the values change in the database? If not, then you might want to examine the actual value of the updateStrsql variable, particularly the WHERE condition. Your UPDATE may not be affecting any records in your database.
 
regarding update sql statement

The update sql is working fine the problem is : on txt1 and txt2, this variables are not getting right values from datagrid, it get the old data not the one which was entered?

Dim txt1 As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text ' Class
Dim txt2 As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text ' V

updateStrsql = "Update RACE_CLASS SET " & _
"RACE_CLASS.CLASS = '" & txt1 & "', " & _
"RACE_CLASS.V = '" & txt2 & "' " & _
"Where RACE_CLASS.ID = '" & e.Item.Cells(3).Text & "' "
 
Back
Top