Question

The Title sounds wierd but thats what is actually happening. I found people with similar problems but there was no answer on these pages. I have a DetailsView Control which is bound to a ObjectDataSource Code:

<asp:DetailsView ID="DetailsView1" runat="server" BackColor="#7B7C95"   BorderColor="White" BorderWidth="1px" CellPadding="2" ForeColor="White" GridLines="None" Style="height: 80%; width: 80%" AutoGenerateRows="False" DataSourceID="UserTableObjectDataSource" Font-Bold="True" Font-Names="Tahoma" AutoGenerateEditButton="True" OnItemUpdating="DetailsView1_ItemUpdating">
    <AlternatingRowStyle BackColor="#393847" />
    <FieldHeaderStyle VerticalAlign="Middle" />
    <Fields>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <div style="width: 50%; height: auto; overflow: auto;">
                    <asp:Image ID="Image1" runat="server" AlternateText="No Image Added" ImageUrl='<%# Eval("ImageUrl") %>' />
                </div>
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        </asp:TemplateField>
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ReadOnly="True" />
        <asp:BoundField DataField="PackagesBooked" HeaderText="Packages Booked" SortExpression="PackagesBooked" ReadOnly="True">
            <ItemStyle Font-Underline="True" />
        </asp:BoundField>
        <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
        <asp:BoundField DataField="PhoneNumber" HeaderText="PhoneNumber" SortExpression="PhoneNumber" />
    </Fields>
    <FooterStyle BackColor="Tan" VerticalAlign="Middle" />
    <HeaderStyle BackColor="Tan" Font-Bold="True" VerticalAlign="Middle" />
    <PagerStyle BackColor="Silver" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
</asp:DetailsView>

<asp:ObjectDataSource ID="UserTableObjectDataSource" runat="server" SelectMethod="getUser" TypeName="HolidaysForYou.DAL.DbHandler" UpdateMethod="updateUser" ValidateRequestMode="Enabled">
    <SelectParameters>
        <asp:SessionParameter Name="username" SessionField="Username" Type="String" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="Email" Type="String" />
        <asp:Parameter Name="PhoneNumber" Type="String" />
        <asp:SessionParameter Name="username" SessionField="Username" Type="String" />
    </UpdateParameters>
</asp:ObjectDataSource>

the update method looks like this

 public static void updateUser(string Email, string PhoneNumber, string username)
        {
            string usernameLower = username.ToLower();
            string queryString = "Update [UserTable] SET Email='" + Email + "',PhoneNumber='" + PhoneNumber + "' WHERE ([Name] = '" + usernameLower + "')";
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                try
                {
                    connection.Open();
                    command.BeginExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }

When i run the program in debug mode and go slowly step by step, the program works perfectly if i just run it there is no change in the Db.

i also tried calling the updateUser function from the DetailsView1_ItemUpdating function like :

 protected void DetailsView1_ItemUpdating(object sender, System.Web.UI.WebControls.DetailsViewUpdateEventArgs e)
        {
            try
            {
                string newEmail = (string)e.NewValues["Email"];
                string newPhoneNumber = (string)e.NewValues["PhoneNumber"];
                if (!UserHomeValidate.userUpdateValidate(newEmail, newPhoneNumber))
                {
                    e.Cancel = true;
                    Error.Visible = true;
                }
                else
                    UserHomeValidate._updateUser(newEmail, newPhoneNumber, Session["Username"].ToString().ToUpper());
            }
            catch (Exception exception)
            {
                Utility.LogFile.CreateLogFile(exception);
            }
        }

where _updateUser is exactly the same as updateUser and still the dataBase is not changed.... this might have something to do with postback but i dont know how that works.. This is getting frustrating a lil help would be appreciated..

No correct solution

OTHER TIPS

Solved the issue... just had to add

if (!Page.IsPostBack)
                    DetailsView1.DataBind();

to the page_Load to avoid binding at the postback as then the old values will be passed...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top