Solved

DetailsView is not updating the database (Multiple tables)

Posted on 2008-06-15
12
901 Views
Last Modified: 2012-06-27
Hi Guys,
The DetailsView is not updating the databse. There is no error message, but after I clicked update, it retures to detailsview with all old data. Anyone please help me. Thanks
<asp:DetailsView ID="DetailsView3" runat="server" AutoGenerateRows="False" BackColor="White"
        BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
        DataSourceID="AccessDataSourceStudentContact" GridLines="None" Height="50px"
        Width="288px" DataKeyNames="Username">
        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
        <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
        <Fields>
            <asp:BoundField DataField="Username" HeaderText="Username" ReadOnly="True" SortExpression="Username" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="LocalPhone" HeaderText="LocalPhone" SortExpression="LocalPhone" />
            <asp:BoundField DataField="LocalWorkPhone" HeaderText="LocalWorkPhone" SortExpression="LocalWorkPhone" />
            <asp:BoundField DataField="PerStreet" HeaderText="PerStreet" SortExpression="PerStreet" />
            <asp:BoundField DataField="PerCity" HeaderText="PerCity" SortExpression="PerCity" />
            <asp:BoundField DataField="PerState" HeaderText="PerState" SortExpression="PerState" />
            <asp:BoundField DataField="PerZip" HeaderText="PerZip" SortExpression="PerZip" />
            <asp:BoundField DataField="PerCountry" HeaderText="PerCountry" SortExpression="PerCountry" />
            <asp:BoundField DataField="LocalStreet" HeaderText="LocalStreet" SortExpression="LocalStreet" />
            <asp:BoundField DataField="LocalCity" HeaderText="LocalCity" SortExpression="LocalCity" />
            <asp:BoundField DataField="LocalState" HeaderText="LocalState" SortExpression="LocalState" />
            <asp:BoundField DataField="LocalZip" HeaderText="LocalZip" SortExpression="LocalZip" />
            <asp:BoundField DataField="AddressUntil" HeaderText="AddressUntil" SortExpression="AddressUntil" />
            <asp:BoundField DataField="CountryName" HeaderText="CountryName" SortExpression="CountryName" />
            <asp:BoundField DataField="CountryCode" HeaderText="CountryCode" SortExpression="CountryCode" />
            <asp:CommandField ShowEditButton="True" />
        </Fields>
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        <HeaderTemplate>
            Contact Information
        </HeaderTemplate>
    </asp:DetailsView>
    <asp:AccessDataSource ID="AccessDataSourceStudentContact" runat="server" DataFile="~/App_Data/GLC.mdb"
        SelectCommand="SELECT Students.Username, Students.Email, Students.LocalPhone, Students.LocalWorkPhone, Address.PerStreet, Address.PerCity, Address.PerState, Address.PerZip, Address.PerCountry, Address.LocalStreet, Address.LocalCity, Address.LocalState, Address.LocalZip, Address.AddressUntil, Countries.CountryName, Countries.CountryCode FROM ((Students INNER JOIN Address ON Students.Username = Address.UserName) INNER JOIN Countries ON Address.PerCountry = Countries.ID) WHERE (Students.Username = @Username)" 
        UpdateCommand="UPDATE Students, Address SET Students.Email = [@Email], Students.LocalPhone = [@LocalPhone], Students.LocalWorkPhone = [@LocalWorkPhone], Address.PerStreet = [@PerStreet], Address.PerCity = [@PerCity], Address.PerState = [@PerState], Address.PerZip = [@PerZip], Address.PerCountry = [@PerCountry], Address.LocalStreet = [@LocalStreet], Address.LocalCity = [@LocalCity], Address.LocalState = [@LocalState], Address.LocalZip = [@LocalZip], Address.AddressUntil = [@AddressUntil]
WHERE ((([Student].[Username])=[@Username]))">
 
     
    <SelectParameters>
       <asp:QUERYSTRINGPARAMETER DefaultValue="0" Name="Students.Username" QueryStringField="ID" />
    </SelectParameters>

Open in new window

0
Comment
Question by:Robertyue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 
LVL 21

Expert Comment

by:naspinski
ID: 21790548
First thing is first: Open sql management studio and make sure your query is working in there.
0
 

Author Comment

by:Robertyue
ID: 21792861
Thank you. I'm using access database. I changed the SQL update command to
"UPDATE Address INNER JOIN Students ON Address.UserName = Students.Username SET Students.Email = @Email, Students.LocalPhone = @LocalPhone, Students.LocalWorkPhone = @LocalWorkPhone, Address.PerStreet = @PerStreet, Address.PerCity = @PerCity, Address.PerState = @PerState, Address.PerZip = @PerZip, Address.PerCountry = @PerCountry, Address.LocalStreet = @LocalStreet, Address.LocalCity = @LocalCity, Address.LocalState = @LocalState, Address.LocalZip = @LocalZip, Address.AddressUntil = @AddressUntil WHERE Student.Username=@Username"
It works fine in Access, but not in DetailsView....
0
 

Author Comment

by:Robertyue
ID: 21792880
I've done other detailviews and they are perfectly updating the database because they have only one table.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 21

Expert Comment

by:naspinski
ID: 21792897
I dont see you declaring any UpdateParameters... all of those need to be declared just like you have your SelectParameters up above.
0
 

Author Comment

by:Robertyue
ID: 21793044
Sorry, I forgot the post the rest...I did declare them..Sorry again


    <UpdateParameters>
     <asp:Parameter Name="Email" Type="String" />
     <asp:Parameter Name="LocalPhone" Type="String" />
     <asp:Parameter Name="LocalWorkPhone" Type="String" />
     <asp:Parameter Name="PerStreet" Type="String" />
     <asp:Parameter Name="PerCity" Type="String" />
     <asp:Parameter Name="PerState" Type="String" />
     <asp:Parameter Name="PerZip" Type="String" />
     <asp:Parameter Name="PerCountry" Type="Int32" />
     <asp:Parameter Name="LocalStreet" Type="String" />
     <asp:Parameter Name="LocalCity" Type="String" />
     <asp:Parameter Name="LocalState" Type="String" />
     <asp:Parameter Name="LocalZip" Type="String" />
     <asp:Parameter Name="AddressUntil" Type="DateTime" />
     
     
     
    </UpdateParameters>
0
 

Author Comment

by:Robertyue
ID: 21793074
Here is the complete version
<asp:DetailsView ID="DetailsView3" runat="server" AutoGenerateRows="False" BackColor="White"
        BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
        DataSourceID="AccessDataSourceStudentContact" GridLines="None" Height="50px"
        Width="288px" DataKeyNames="Username">
        <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
        <EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
        <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
        <Fields>
            <asp:BoundField DataField="Username" HeaderText="Username" ReadOnly="True" SortExpression="Username" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:BoundField DataField="LocalPhone" HeaderText="LocalPhone" SortExpression="LocalPhone" />
            <asp:BoundField DataField="LocalWorkPhone" HeaderText="LocalWorkPhone" SortExpression="LocalWorkPhone" />
            <asp:BoundField DataField="PerStreet" HeaderText="PerStreet" SortExpression="PerStreet" />
            <asp:BoundField DataField="PerCity" HeaderText="PerCity" SortExpression="PerCity" />
            <asp:BoundField DataField="PerState" HeaderText="PerState" SortExpression="PerState" />
            <asp:BoundField DataField="PerZip" HeaderText="PerZip" SortExpression="PerZip" />
            <asp:BoundField DataField="PerCountry" HeaderText="PerCountry" SortExpression="PerCountry" />
            <asp:BoundField DataField="LocalStreet" HeaderText="LocalStreet" SortExpression="LocalStreet" />
            <asp:BoundField DataField="LocalCity" HeaderText="LocalCity" SortExpression="LocalCity" />
            <asp:BoundField DataField="LocalState" HeaderText="LocalState" SortExpression="LocalState" />
            <asp:BoundField DataField="LocalZip" HeaderText="LocalZip" SortExpression="LocalZip" />
            <asp:BoundField DataField="AddressUntil" HeaderText="AddressUntil" SortExpression="AddressUntil" />
            <asp:BoundField DataField="CountryName" HeaderText="CountryName" SortExpression="CountryName" />
            <asp:BoundField DataField="CountryCode" HeaderText="CountryCode" SortExpression="CountryCode" />
            <asp:CommandField ShowEditButton="True" />
        </Fields>
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
        <HeaderTemplate>
            Contact Information
        </HeaderTemplate>
    </asp:DetailsView>
    <asp:AccessDataSource ID="AccessDataSourceStudentContact" runat="server" DataFile="~/App_Data/GLC.mdb"
        SelectCommand="SELECT Students.Username, Students.Email, Students.LocalPhone, Students.LocalWorkPhone, Address.PerStreet, Address.PerCity, Address.PerState, Address.PerZip, Address.PerCountry, Address.LocalStreet, Address.LocalCity, Address.LocalState, Address.LocalZip, Address.AddressUntil, Countries.CountryName, Countries.CountryCode FROM ((Students INNER JOIN Address ON Students.Username = Address.UserName) INNER JOIN Countries ON Address.PerCountry = Countries.ID) WHERE (Students.Username = @Username)" 
        UpdateCommand="UPDATE (Address INNER JOIN Students ON Address.UserName = Students.Username) SET Students.Email = @Email, Students.LocalPhone = @LocalPhone, Students.LocalWorkPhone = @LocalWorkPhone, Address.PerStreet = @PerStreet, Address.PerCity = @PerCity, Address.PerState = @PerState, Address.PerZip = @PerZip, Address.PerCountry = @PerCountry, Address.LocalStreet = @LocalStreet, Address.LocalCity = @LocalCity, Address.LocalState = @LocalState, Address.LocalZip = @LocalZip, Address.AddressUntil = @AddressUntil WHERE (Student.Username=@Username)">
 
     
    <SelectParameters>
       <asp:QUERYSTRINGPARAMETER DefaultValue="0" Name="Students.Username" QueryStringField="ID" />
    </SelectParameters>
    
    <UpdateParameters>
     <asp:Parameter Name="Email" Type="String" />
     <asp:Parameter Name="LocalPhone" Type="String" />
     <asp:Parameter Name="LocalWorkPhone" Type="String" />
     <asp:Parameter Name="PerStreet" Type="String" />
     <asp:Parameter Name="PerCity" Type="String" />
     <asp:Parameter Name="PerState" Type="String" />
     <asp:Parameter Name="PerZip" Type="String" />
     <asp:Parameter Name="PerCountry" Type="Int32" />
     <asp:Parameter Name="LocalStreet" Type="String" />
     <asp:Parameter Name="LocalCity" Type="String" />
     <asp:Parameter Name="LocalState" Type="String" />
     <asp:Parameter Name="LocalZip" Type="String" />
     <asp:Parameter Name="AddressUntil" Type="DateTime" />
     
    </UpdateParameters>
    
    </asp:AccessDataSource>

Open in new window

0
 
LVL 21

Accepted Solution

by:
naspinski earned 500 total points
ID: 21793094
I dont see username in there.  I know it is a readonly, but it still needs to be declared.

Try adding that in.
0
 

Author Comment

by:Robertyue
ID: 21793220
I did add it in but it's still not working. I didn't declare Username for my another single table detailsview and it works.  Thanks
0
 

Author Comment

by:Robertyue
ID: 21793234
Is my SQL Update command wrong? It works in Access. The format is wrong in ASP.Net, may be?
0
 

Author Comment

by:Robertyue
ID: 21793284
Please see attachment. This is my database and there is only one query (update). Please enter "hao" as the Uername. Why it's asking me to enter the username for both "Students.Username" and "@Username"? Should it ask me to only enter "@Username", then the database compares the entry with records to find out the data? Thanks
GLC.mdb
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21793298
Sorry, I have to get going today, but I can take a look at it in about 12 hours if someone doesn't beat me to it.
0
 

Author Comment

by:Robertyue
ID: 21809504
Hello, you back? Could you please take a look my databse? Thanks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 44
asp.net figure out error 3 47
Consume a webservice via VB in Visual Studio 2015 3 47
ASP.net Moving Visual Studio 2015 project to 2017 2 71
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question