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'
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table border="0" cellpadding="3" cellspacing="0" align="center">
<tr class="tableRow">
<td class="tableCell">
Location:
</td>
<td class="tableCell">
<asp:HiddenField ID="hdnID" runat="server" Value='<%# bind("LocationID") %>' />
<telerik:RadComboBox ID="rcmbLocation" runat="server" Text='<%# bind("LocationID") %>'
DataSourceID="dsrcmbLocation" DataTextField="Location" DataValueField="LocationID"
Height="150px">
</telerik:RadComboBox>
<asp:RequiredFieldValidator ID="rfvDesc" ControlToValidate="rcmbLocation" ErrorMessage="Please Select the Clinic"
runat="server" ValidationGroup="Update" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr class="tableRow">
<td class="tableCell">
Kube Location:</td>
<td class="tableCell">
<asp:TextBox ID="txtKubeLocation" runat="server" Text='<%# bind("KubeLocation") %>' Class="forTextBox"
MaxLength="4" onkeypress="return filterInput(2,event);">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfvKubeLoc" ControlToValidate="txtKubeLocation" ErrorMessage="Please Enter KubeLocation"
runat="server" ValidationGroup="Update" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr class="tableRow">
<td class="tableCell">
CSV Code:</td>
<td class="tableCell">
<asp:TextBox ID="txtCSVCode" runat="server" Text='<%# bind("CSVCode") %>' Class="forTextBox"
MaxLength="4" onkeypress="return filterInput(2,event);">
</asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCSVCode" ControlToValidate="txtCSVCode" ErrorMessage="Please Enter the CSV Code"
runat="server" ValidationGroup="Update" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<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