0 Replies - 1492 Views - Last Post: 20 September 2012 - 04:42 PM Rate Topic: -----

#1 gns1497  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 27-June 12

Updating SQL database from webform is not working

Posted 20 September 2012 - 04:42 PM

Hello everyone. Still relatively new to .Net/ASP and am in a bind trying to meet a deadline and hoping someone can help. Using VB.net/ASP updating a SQL Server db and have done so successfully with another table in this project, but this one is a bit different and I'm looking for a way make this work, but am really pressed for time, so here goes.

I'm trying to update a table that pulls 2 fields from another table together via a join on the primary key.

The table I am updating is called the tblfldOnCallAnalyst table. This table has the fields fldGroupName, fldStartOnCall, fldEndOnCall, fldRank, and 'Analyst'.

'Analyst' is an alias I've used to combine 2 fields from Table 2 (tblEmployee). The fields are fldEmpLastName and fldEmpFirstName with a comma and space separating them in the string. The inner join I used cross references the numbered primary key in the tblEmployee table and translates that string from the key. What is the best way to update from this aliased field (using a dropdown box populated from a datasource reading this join) from my asp form? My code is as follows...

Begin ASP Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Dictionaries.aspx.vb" Inherits="Dictionaries" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> Edit OnCall Schedule </title>
    <style type="text/css">
        #form1
        {
            height: 731px;
            width: 1122px;
        }
    </style>
</head>
<body>
    <form id="frmDictionaries" method="post" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server">
                        </asp:ToolkitScriptManager> 
    <div>
    
    </div>
    <asp:SqlDataSource ID="dsOncallGroup" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DiscussSQLConnectionString %>" 
                        
        SelectCommand="SELECT tblOnCallAnalystSchedule.fldOnCallGroup, tblOnCallAnalystSchedule.fldStartOnCall, 
                        tblOnCallAnalystSchedule.fldEndOnCall, tblOnCallAnalystSchedule.fldRank, tblOnCallAnalystSchedule.fldOnCallAnalyst,
                        tblEmployee.fldEmpLastName +', ' + tblEmployee.fldEmpFirstName as 'Analyst'
                       FROM tblEmployee INNER JOIN tblOnCallAnalystSchedule 
                       ON tblEmployee.fldEmpID = tblOnCallAnalystSchedule.fldOnCallAnalyst 
                       WHERE (tblOnCallAnalystSchedule.fldOnCallGroup = @fldOnCallGroup) 
                       AND (tblOnCallAnalystSchedule.fldEndOnCall > GETDATE()) 
                       ORDER BY tblOnCallAnalystSchedule.fldOnCallGroup, tblOnCallAnalystSchedule.fldEndOnCall, 
                       tblOnCallAnalystSchedule.fldRank" 
        OldValuesParameterFormatString="original_{0}" 
        ConflictDetection="CompareAllValues" 
        DeleteCommand="DELETE FROM [tblOnCallAnalystSchedule] WHERE [fldOnCallGroup] = @original_fldOnCallGroup AND [fldStartOnCall] = @original_fldStartOnCall AND [fldEndOnCall] = @original_fldEndOnCall AND [fldRank] = @original_fldRank AND (([fldOnCallAnalyst] = @original_fldOnCallAnalyst) OR ([fldOnCallAnalyst] IS NULL AND @original_fldOnCallAnalyst IS NULL))" 
        InsertCommand="INSERT INTO [tblOnCallAnalystSchedule] ([fldOnCallGroup], [fldStartOnCall], [fldEndOnCall], [fldRank], [fldOnCallAnalyst]) VALUES (@fldOnCallGroup, @fldStartOnCall, @fldEndOnCall, @fldRank, @fldOnCallAnalyst)" 
        
        
        
        UpdateCommand="UPDATE [tblOnCallAnalystSchedule] SET [fldStartOnCall] = @fldStartOnCall, 
                       [fldEndOnCall] = @fldEndOnCall, [fldRank] = @fldRank, [fldOnCallAnalyst] = @fldOnCallAnalyst
                       WHERE [fldOnCallAnalyst] = @fldOnCallAnalyst">
                       
        <SelectParameters>
            <asp:ControlParameter ControlID="cboOncallGroup" Name="fldOnCallGroup" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_fldOnCallGroup" Type="String" />
            <asp:Parameter DbType="DateTime2" Name="original_fldStartOnCall" />
            <asp:Parameter DbType="DateTime2" Name="original_fldEndOnCall" />
            <asp:Parameter Name="original_fldRank" Type="Int32" />
            <asp:Parameter Name="original_fldOnCallAnalyst" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="fldOnCallGroup" Type="String" ConvertEmptyStringToNull="false" />
            <asp:Parameter DbType ="DateTime2" Name="fldStartOnCall" />
            <asp:Parameter DbType ="DateTime2" Name="fldEndOnCall" />
            <asp:Parameter Name="fldRank" Type="Int32" />
            <asp:Parameter Name="fldOnCallAnalyst" Type="Int32" />
            <asp:Parameter Name="original_fldOnCallGroup" Type="String" ConvertEmptyStringToNull="false" />
            <asp:Parameter DbType="DateTime2" Name="original_fldStartOnCall" />
            <asp:Parameter DbType="DateTime2" Name="original_fldEndOnCall" />
            <asp:Parameter Name="original_fldRank" Type="Int32" />
            <asp:Parameter Name="original_fldOnCallAnalyst" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="fldOnCallGroup" Type="String" />
            <asp:Parameter DbType="DateTime2" Name="fldStartOnCall" />
            <asp:Parameter DbType="DateTime2" Name="fldEndOnCall" />
            <asp:Parameter Name="fldRank" Type="Int32" />
            <asp:Parameter Name="fldOnCallAnalyst" Type="Int32" />
        </InsertParameters>
    </asp:SqlDataSource>
    
    
    <asp:SqlDataSource ID="dsListbox" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DiscussSQLConnectionString %>" 
        SelectCommand="SELECT DISTINCT [fldOnCallGroup] FROM [tblOnCallAnalystSchedule]">
    </asp:SqlDataSource>
    
     <asp:SqlDataSource ID="dsAnalyst" runat="server"
        
        ConnectionString="<%$ ConnectionStrings:DiscussSQLConnectionString %>" 
                        
        SelectCommand="SELECT DISTINCT tblEmployee.fldEmpLastName +', ' + tblEmployee.fldEmpFirstName as 'Analyst'
                       FROM tblEmployee INNER JOIN tblOnCallAnalystSchedule 
                       ON tblEmployee.fldEmpID = tblOnCallAnalystSchedule.fldOnCallAnalyst 
                       WHERE (tblOnCallAnalystSchedule.fldOnCallGroup = @fldOnCallGroup) 
                       AND (tblOnCallAnalystSchedule.fldEndOnCall > GETDATE())">       
                       
       <SelectParameters>
            <asp:ControlParameter ControlID="cboOncallGroup" Name="fldOnCallGroup" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
                        
                       
                       
    </asp:SqlDataSource>
    
    
  
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Image ID="Image1" runat="server" Height="87px" 
        ImageUrl="~/images/HCA.jpg" Width="224px" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
    
    <asp:DropDownList ID="cboOncallGroup" runat="server" DataSourceID="dsListbox" DataTextField="fldOnCallGroup" 
        DataValueField="fldOnCallGroup" AppendDataBoundItems="true" onselectedIndexChanged="cboOnCallGroup_SelectedIndexChanged" AutoPostBack="true" Height="19px" Width="237px">
    </asp:DropDownList>
    
    
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Image ID="imgDISCuSS" runat="server" Height="42px" 
        ImageUrl="~/images/DISCuSS.jpg" style="margin-top: 3px" Width="131px" />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="cmdEditEmployee" runat="server" Text="Edit Employee" 
        Width="107px" Font-Size="X-Small" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="cmdEditSchedule" runat="server" Text="Edit Schedule" 
            Width="107px" Font-Size="X-Small" />
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="cmdEditMgrSchedule" runat="server" Text="Edit Mgr Schedule" 
            Width="107px" Font-Size="X-Small" />
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="cmdMain" runat="server" Text="Main Menu" 
            Width="107px" Font-Size="X-Small" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
    <br />
    <div style="margin-left: 240px">
        <asp:Gridview ID="gvOnCallSchedule" runat="server" AllowSorting="True" AllowPaging="True" showfooter="true"
            OnRowUpdating="GvOnCall_Update" DataKeyNames="fldOnCallGroup"
            BackColor="Aqua" DataSourceID="dsOncallGroup" Font-Bold="True" 
            Font-Italic="False" Font-Overline="False" Font-Strikeout="False" 
            Font-Underline="False" ForeColor="#333333" HorizontalAlign="Justify" 
            CellPadding="4" GridLines="None" PageSize="20" AutoGenerateColumns ="false" Allowusertoaddrows="true" 
            onselectedIndexChanged="cboOnCallGroup_SelectedIndexChanged">
            
            <Columns>
                <asp:TemplateField ShowHeader="false"> 
                    <FooterTemplate>
                        <asp:ImageButton ID="AddButton" runat="server" CommandName="Insert" ImageURL="~/images/New.png" 
                             Text="Add" ToolTip="Add New On Call Record" />                
                    </FooterTemplate>
                    
                    <EditItemTemplate>
                            <asp:ImageButton ID="UpdateButton" runat="server" CausesValidation="False" CommandName="Update" 
                                    ImageUrl="~/images/Save.png" Text="Update" ToolTip="Update" />
                                    &nbsp;
                            <asp:ImageButton ID="CancelButton" runat="server" CausesValidation="false" CommandName="Cancel"
                                    ImageURL="~/images/Cancel.png" Text="Cancel" ToolTip="Cancel" />
                    </EditItemTemplate>
                    
                    <ItemTemplate>
                        <asp:ImageButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" 
                                    ImageUrl="~/images/Edit.gif" Text="Edit" ToolTip="Edit" />
                                    &nbsp;
                        <asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" 
                                    ImageUrl="~/images/Delete.png" Text="Delete" ToolTip="Delete" />
                    </ItemTemplate>
                    <ItemStyle Wrap="false" />   
                </asp:TemplateField>                          
                                                      
                
                <asp:TemplateField headertext="On Call Group">
                    <ItemTemplate>
                        <asp:Label ID="lblOnCallGroup" runat="server" Width="250px" Wrap="false" Text='<%# Bind("fldOnCallGroup") %>'> 
                            </asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>              
                        <asp:Label ID="txtOnCallGroup" runat="server" Width="250px" Wrap="false" Text='<%# Bind("fldOnCallGroup") %>'> 
                            </asp:Label>
                    </FooterTemplate> 
                </asp:TemplateField>
                
                
                <asp:TemplateField headertext="Start Date/Time">
                    <ItemTemplate>
                        <asp:Textbox ID="txtStartOnCall" runat="server" Text='<%# Bind("fldStartOnCall") %>'> 
                            </asp:Textbox>
                        <asp:Image ID="calpopup" runat="server" ImageUrl="~/images/calendar2.png" />
                        <asp:CalendarExtender ID="StartOnCallCal" runat="server" TargetControlID="txtStartOnCall" 
                                PopupButtonID="calpopup" PopupPosition="Right" format="MM/dd/yyyy hh:mm:ss tt">
                        </asp:CalendarExtender>
                    </ItemTemplate>
                    <FooterTemplate>              
                        <asp:Textbox ID="txtStartOnCallFtr" runat="server" Text='<%# Bind("fldStartOncall") %>'> 
                            </asp:Textbox>
                        <asp:Image ID="calpopupFtr" runat="server" ImageUrl="~/images/calendar2.png" />    
                        <asp:CalendarExtender ID="StartOnCallCalFtr" runat="server" TargetControlID="txtStartOnCallFtr" 
                                PopupButtonID="calpopupFtr" PopupPosition="Right" format="MM/dd/yyyy hh:mm:ss tt">
                        </asp:CalendarExtender>
                        
                    </FooterTemplate> 
                </asp:TemplateField>
                
                <asp:TemplateField headertext="End Date/Time">
                    <ItemTemplate>
                        <asp:Textbox ID="txtEndOnCall" runat="server" Text='<%# Bind("fldEndOnCall") %>'> 
                            </asp:Textbox>
                        <asp:Image ID="calpopup2" runat="server" ImageUrl="~/images/calendar2.png" />
                        <asp:CalendarExtender ID="EndOnCallCal" runat="server" TargetControlID="txtEndOnCall" 
                                PopupButtonID="calpopup2" PopupPosition="Right" format="MM/dd/yyyy hh:mm:ss tt">
                        </asp:CalendarExtender>
                    </ItemTemplate>
                    <FooterTemplate>              
                        <asp:Textbox ID="txtEndOnCallFtr" runat="server" Text='<%# Bind("fldEndOnCall") %>'> 
                            </asp:Textbox>
                        <asp:Image ID="calpopup2Ftr" runat="server" ImageUrl="~/images/calendar2.png" />    
                        <asp:CalendarExtender ID="EndOnCallCalFtr" runat="server" TargetControlID="txtEndOnCallFtr" 
                                PopupButtonID="calpopup2Ftr" PopupPosition="Right" format="MM/dd/yyyy hh:mm:ss tt">
                        </asp:CalendarExtender>
                        
                    </FooterTemplate> 
                </asp:TemplateField>
                
                                               
                <asp:TemplateField headertext="Call Order">
                    <ItemTemplate>
                        <asp:Textbox ID="lblCallOrder" runat="server" Text='<%# Bind("fldRank") %>'> 
                            </asp:Textbox>
                    </ItemTemplate>
                    <FooterTemplate>              
                        <asp:Textbox ID="txtCallOrderFtr" runat="server" Text='<%# Bind("fldOnCallGroup") %>'> 
                            </asp:Textbox>
                    </FooterTemplate> 
                </asp:TemplateField>
                
                <asp:TemplateField headertext="EmpID">
                    <ItemTemplate>
                        <asp:Label ID="txtOnCallAnalyst" runat="server" Text='<%# Bind("fldOnCallAnalyst") %>'> </asp:Label>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="ftrtxtOnCallAnalyst" runat="server" Text='<%# Bind("fldOncallAnalyst") %>'> </asp:Label>
                    </FooterTemplate>
                </asp:TemplateField>
                
                                                  
                <asp:TemplateField HeaderText="On Call Analyst">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddlAnalyst" runat="server" datavaluefield="Analyst"
                            DataSourceID= "dsAnalyst" SelectedValue="<%# Bind('Analyst') %>"> 
                        </asp:DropDownList>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlAnalyst" runat="server" datavaluefield="Analyst"
                            DataSourceID= "dsAnalyst" SelectedValue="<%# Bind('Analyst') %>"> 
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                
   
                
            </Columns>
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#7C6F57" />
            <AlternatingRowStyle BackColor="White" />
            
        </asp:Gridview>
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
    <br />
    <div style="margin-left: 200px">
    </div>
    </form>
    </body>
</html>





Begin VB Codebehind:
Protected Sub cboOnCallGroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboOncallGroup.SelectedIndexChanged
        'Dim cboAssignedFK As DropDownList = DirectCast(sender, DropDownList)
        Dim cboOnCallGroup As String = TryCast(sender, DropDownList).SelectedValue
        Dim sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrin  gs("DiscussSQLConnectionString").ConnectionString)
        Dim sSql As System.Xml.Linq.XElement = <sql>

            SELECT [fldOnCallGroup], [fldStartOnCall], [fldEndOnCall], [fldRank], [fldOnCallAnalyst] 
            FROM [tblOnCallAnalystSchedule]

            WHERE ([fldOnCallGroup] = '<%= cboOnCallGroup %>') 
            ORDER BY [fldOnCallGroup], [fldEndOnCall], [fldRank] </sql>


        Dim sqlCmd As New SqlCommand(sSql.Value, sqlConn)
        Dim sqlRead As SqlDataReader
        If sqlConn.State <> ConnectionState.Open Then
            sqlConn.Open()
        End If
        sqlRead = sqlCmd.ExecuteReader()
        sqlRead.Read()

        sqlRead.Close()
        sqlConn.Close()
    End Sub

    Function SendSQLCommand(ByVal tsSQLCmd As String, ByVal tsqlConn As SqlConnection) As Integer
        Dim iRetVal As Integer = -1
        Dim sqlCmd As New SqlCommand(tsSQLCmd, tsqlConn)
        If tsqlConn.State <> ConnectionState.Open Then
            tsqlConn.Open()
        End If
        Try
            iRetVal = sqlCmd.ExecuteNonQuery()
        Catch ex As Exception
            Throw ex
        End Try
        Return iRetVal
    End Function
    Protected Sub GvOnCall_Update(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)  
        'Dim MgrPass As String
        Dim keyValue As String = e.Keys("fldOnCallGroup").ToString()

        Dim strfldStartOnCallOld As String = RTrim(LTrim(e.OldValues("fldStartOnCall").ToString()))
        Dim strfldStartOnCallNew As String = RTrim(LTrim(e.NewValues("fldStartOnCall").ToString()))

        Dim strfldEndOnCallOld As String = RTrim(LTrim(e.OldValues("fldEndOnCall").ToString()))
        Dim strfldEndOnCallNew As String = RTrim(LTrim(e.NewValues("fldEndOnCall").ToString()))

        Dim strfldRankOld As String = RTrim(LTrim(e.OldValues("fldRank").ToString()))
        Dim strfldRankNew As String = RTrim(LTrim(e.NewValues("fldRank").ToString()))

        Dim strfldOnCallAnalystOld As Int32 = RTrim(LTrim(e.OldValues("fldOnCallAnalyst")))
        Dim strfldOnCallAnalystNew As Int32 = RTrim(LTrim(e.NewValues("fldOnCallAnalyst")))



        'MgrPass = InputBox("Please enter the manager password.", "Password Required")

        'If MgrPass = "manage" Then
        gvOnCall_Updated(keyValue, strfldStartOnCallNew, strfldEndOnCallNew, strfldRankNew, strfldOnCallAnalystNew)
        'Else
        'MsgBox("Only CSS managers may edit DISCuSS.", MsgBoxStyle.Critical, "Authentication Failed")
        'End If

        'http://support.microsoft.com/kb/301248
        'http://www.codeproject.com/Questions/334429/how-to-create-a-combobox-in-grid-view-control

    End Sub

    Protected Sub gvOnCall_Updated(ByVal fldOnCallGroup As String, ByVal fldStartOnCall As String, ByVal fldEndOnCall As String, _
                                   ByVal fldRank As String, ByVal fldOnCallAnalyst As Int32)
        Dim sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrin  gs("DiscussSQLConnectionString").ConnectionString)
        Dim sSql As XElement
        sSql = <sql>
            Update [tblOncallAnalystSchedule] SET [fldOnCallGroup] = '<%= fldOnCallGroup %>', 
                   [fldStartOnCall] = '<%= [fldStartOnCall] %>',[fldEndOnCall] = '<%= [fldEndOnCall] %>', 
                   [fldRank] = '<%= [fldRank] %>', [fldOnCallAnalyst] = '<%= [fldOnCallAnalyst] %>'
            Where [fldOnCallGroup] = '<%= [fldOnCallGroup] %>' </sql>

        'MsgBox(Err.Description, MsgBoxStyle.Critical, "SQL Error")

        SendSQLCommand(sSql.Value, sqlConn)
        sqlConn.Close()
    End Sub
End Class





The error I get when performing the update on the form is:

Violation of PRIMARY KEY constraint 'tblOnCallAnalystSchedule$PrimaryKey'. Cannot insert duplicate key in object 'dbo.tblOnCallAnalystSchedule'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'tblOnCallAnalystSchedule$PrimaryKey'. Cannot insert duplicate key in object 'dbo.tblOnCallAnalystSchedule'.
The statement has been terminated.

Source Error:


Line 60: iRetVal = sqlCmd.ExecuteNonQuery()
Line 61: Catch ex As Exception
Line 62: Throw ex
Line 63: End Try
Line 64: Return iRetVal
------------------------------------------------


Screenshot attached of how the table I am updating Attached Imagelooks in SQL. What's confusing to me is that its shows 4 primary keys in the Columns, but in the Keys, only 1 is shown as a primary key? Could this be my problem?

Any help or direction given is greatly appreciated. Thank you for your time.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1