hi am trying to write a code in which i need to perform a update but on primary keys how do i achieve it
i have written the following code: kindly look at it let me know where m wrong
Protected Sub rgKMSLoc_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgKMSLoc.UpdateCommand
Try
KAYAReqConn.Open()
If TypeOf e.Item Is GridEditableItem Then
Dim strItemID As String = CType(e.Item.FindControl("hdnID"), HiddenField).Value
Dim strrcmbLocation As String = CType(e.Item.FindControl("rcmbLocation"), RadComboBox).SelectedValue
Dim strKubeLocation As String = CType(e.Item.FindControl("txtKubeLocation"), TextBox).Text
Dim strCSVCode As String = CType(e.Item.FindControl("txtCSVCode"), TextBox).Text
SQLCmd = New SqlCommand("SELECT * FROM MstKMSLocKubeLocMapping WHERE LocationID= '" & rcmbLocation.SelectedValue & "'", KAYAReqConn)
Dim dr As SqlDataReader
dr = SQLCmd.ExecuteReader
If dr.HasRows Then
lblMsgWarning.Text = "<font color=red>""User ID Already Exists"
Exit Sub
End If
dr.Close()
SQLCmd = New SqlCommand("UPDATE MstKMSLocKubeLocMapping SET LocationID=@Location,KubeLocation=@KubeLocation,CSVCode=@CSVCode WHERE LocationID = '" & strItemID & "'", KAYAReqConn)
SQLCmd.Parameters.AddWithValue("@Location", Replace(strrcmbLocation, "'", "''"))
SQLCmd.Parameters.AddWithValue("@KubeLocation", Replace(strKubeLocation, "'", "''"))
SQLCmd.Parameters.AddWithValue("@CSVCode", Replace(strCSVCode, "'", "''"))
SQLCmd.Parameters.AddWithValue("@Status", "A")
SQLCmd.ExecuteNonQuery()
lblMessageUpdate.Text = "<font color=blue>""Record Updated SuccessFully"
SQLCmd.Dispose()
rgKMSLoc.Rebind()
End If
Catch ex As Exception
Response.Write(ex.ToString)
Finally
KAYAReqConn.Close()
End Try
End Sub
this is my designer page'
Location:
' /
'
DataSourceID="dsrcmbLocation" DataTextField="Location" DataValueField="LocationID"
Height="150px"
Kube Location:
' Class="forTextBox"
MaxLength="4" onkeypress="return filterInput(2,event);"
CSV Code:
' Class="forTextBox"
MaxLength="4" onkeypress="return filterInput(2,event);"
<tr class="tableRow">
<td colspan="2" align="center" class="tableCell">
<asp:ImageButton ID="btnUpdate" runat="server" CommandName="Update" CausesValidation="true"
ValidationGroup="Update" ImageUrl="~/Images/update.gif"></asp:ImageButton>
<asp:ImageButton ID="btnCancel" runat="server" CausesValidation="false" CommandName="Cancel"
ImageUrl="~/Images/No.gif"></asp:ImageButton>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
Locationid is my primary key