Advertisement

03.12.2008 at 02:37PM PDT, ID: 23236841
[x]
Attachment Details

Error on update of Datalist

Asked by csg_int_it in .NET, Programming for ASP.NET

Tags: ASP.NET VB.NET, IE7

I have a datalist which displays users info and in the edit template the user has the ability to edit the users information.  I am having a problem with the update of the records.  I can navigate around and cancel stuff out but when I go to save/update I get an error, and its a worthless error.  Here is what I have for my code:Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
<script> 
    Protected Sub dlContacts_EditCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
        dlContacts.EditItemIndex = e.Item.ItemIndex
        dlContacts.DataBind()
    End Sub
    
    Protected Sub dlContacts_DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
        srcContacts.DeleteParameters("fcntct_id").DefaultValue = dlContacts.DataKeys(e.Item.ItemIndex).ToString()
        srcContacts.Delete()
    End Sub
    
    Protected Sub dlContacts_CancelCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
        dlContacts.EditItemIndex = -1
        dlContacts.DataBind()
    End Sub
    
    Protected Sub dlContacts_UpdateCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
        Dim txtFirstName As TextBox = CType(e.Item.FindControl("fcntct_fname"), TextBox)
        Dim txtLastName As TextBox = CType(e.Item.FindControl("fcntct_lname"), TextBox)
        Dim txtEmail As TextBox = CType(e.Item.FindControl("fcntct_email"), TextBox)
      
        srcContacts.UpdateParameters("fcntct_id").DefaultValue = dlContacts.DataKeys(e.Item.ItemIndex)
        srcContacts.UpdateParameters("fcntct_fname").DefaultValue = txtFirstName.Text
        srcContacts.UpdateParameters("fcntct_lname").DefaultValue = txtLastName.Text
        srcContacts.UpdateParameters("fcntct_email").DefaultValue = txtEmail.Text
        
        'update the datasource
        srcContacts.DataBind()
        
        'take out of edit mode
        dlContacts.EditItemIndex = -1
        
    End Sub
</script>
 
<asp:SqlDataSource ID="srcCustomers" runat="server" ConnectionString="<%$ ConnectionStrings:USASqlServer %>"
    SelectCommand="SELECT cm_addr + ' - ' + cm_sort AS [name], cm_addr, cm_sort&#13;&#10;FROM cm_mstr">
</asp:SqlDataSource>
<asp:SqlDataSource ID="srcContacts" runat="server" ConnectionString="<%$ ConnectionStrings:FastSqlServer %>"
    DeleteCommand="DELETE FROM [fcntct_mstr] WHERE [fcntct_id] = @fcntct_id" 
    InsertCommand="INSERT INTO [fcntct_mstr] ([fcntct_fname], [fcntct_lname], [fcntct_email]) VALUES (@fcntct_fname, @fcntct_lname, @fcntct_email)"
    SelectCommand="SELECT [fcntct_fname], [fcntct_lname], [fcntct_email], [fcntct_id] FROM [fcntct_mstr]"
    UpdateCommand="UPDATE [fcntct_mstr] SET [fcntct_fname] = @fcntct_fname, [fcntct_lname] = @fcntct_lname, [fcntct_email] = @fcntct_email WHERE [fcntct_id] = @fcntct_id">
    <DeleteParameters>
        <asp:Parameter Name="fcntct_id" Type="Int16" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="fcntct_fname" />
        <asp:Parameter Name="fcntct_lname" />
        <asp:Parameter Name="fcntct_email" />
        <asp:Parameter Name="fcntct_id" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter Name="fcntct_fname" Type="String" />
        <asp:Parameter Name="fcntct_lname" Type="String" />
        <asp:Parameter Name="fcntct_email" Type="String" />
    </InsertParameters>
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="srcCustomers" DataTextField="name"
    DataValueField="cm_addr" >
</asp:DropDownList>
<br />
<br />
<asp:DataList ID="dlContacts" runat="server" 
            DataKeyField="fcntct_id" 
            DataSourceID="srcContacts"
            OnEditCommand="dlContacts_EditCommand" 
            OnCancelCommand="dlContacts_CancelCommand"
            OnDeleteCommand="dlContacts_DeleteCommand"
            OnUpdateCommand="dlContacts_UpdateCommand" >
    <EditItemTemplate>
        <asp:ImageButton
            ID="btnSave"
            CommandName="Update"
            ImageUrl="~/images/save.gif"
            AlternateText="Save Contact"
            runat="server" />&nbsp;&nbsp;  
        <asp:ImageButton
            ID="btnCancel"
            CommandName="Cancel"
            AlternateText="Cancel" 
            ImageUrl="~/images/cancel2.gif"
            OnClientClick="return confirm('Cancel without save?');"
            runat="server" /><br /><br />
        fcntct_fname:
        <asp:Textbox ID="fcntct_fnameLabel" runat="server" Style="position: static" Text='<%# Eval("fcntct_fname") %>'></asp:Textbox><br />
        fcntct_lname:
        <asp:Textbox ID="fcntct_lnameLabel" runat="server" Style="position: static" Text='<%# Eval("fcntct_lname") %>'></asp:Textbox><br />
        fcntct_email:
        <asp:Textbox ID="fcntct_emailLabel" runat="server" Style="position: static" Text='<%# Eval("fcntct_email") %>'></asp:Textbox>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:ImageButton 
                ID="btnEdit" 
                CommandName="Edit"
                AlternateText="Edit Contact" 
                ImageUrl="~/images/edit.gif"
                runat="server" />&nbsp;
        <asp:ImageButton 
                ID="btnDelete"
                CommandName="Delete" 
                AlternateText="Delete Contact"
                OnClientClick="return confirm('Are you sure?');"
                ImageUrl="~/images/delete.gif"
                runat="server" />
        <br /><br />
        fcntct_fname:
        <asp:Label ID="fcntct_fnameLabel" runat="server" Text='<%# Eval("fcntct_fname") %>'></asp:Label><br />
        fcntct_lname:
        <asp:Label ID="fcntct_lnameLabel" runat="server" Text='<%# Eval("fcntct_lname") %>'></asp:Label><br />
        fcntct_email:
        <asp:Label ID="fcntct_emailLabel" runat="server" Text='<%# Eval("fcntct_email") %>'></asp:Label><br />
        fcntct_id:
        <asp:Label ID="fcntct_idLabel" runat="server" Text='<%# Eval("fcntct_id") %>'></asp:Label>
    </ItemTemplate>
</asp:DataList>
[+][-]03.12.2008 at 02:53PM PDT, ID: 21111183

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 06:33PM PDT, ID: 21112616

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 06:36PM PDT, ID: 21112628

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Programming for ASP.NET
Tags: ASP.NET VB.NET, IE7
Sign Up Now!
Solution Provided By: RDdice
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.12.2008 at 06:50PM PDT, ID: 21112692

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 06:52PM PDT, ID: 21112702

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 07:20PM PDT, ID: 21112830

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628