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
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