Solved

How to save the date entered in textbox to database?

Posted on 2010-11-26
8
679 Views
Last Modified: 2012-05-10
Hi,

I'm building a web app that has a connection with Microsoft Dynamics NAV 2009. On one of the pages you have to enter a starting date and an ending date in a textbox. By default the textboxes are filled with today's date. When I click on the save button, the date isn't saved.

<td valign="middle" class="ProjectCardLabel">
                            <asp:Label ID="lblStartingDate" runat="server" Text="Starting Date:"></asp:Label>
                        </td>
                        <td class="ProjectCardData">
                            <asp:TextBox ID="txtStartingDate" runat="server" Columns="10" MaxLength="10" 
                                style="background-image: url('images/png/calendarpicker_18x18.png'); background-repeat: no-repeat; background-position: right center;" 
                                TabIndex="15"></asp:TextBox>
                        </td>
                        <td>&nbsp;</td>
                        <td valign="middle" class="ProjectCardLabel">
                            <asp:Label ID="lblEndingDate" runat="server" Text="Ending Date:"></asp:Label>
                        </td>
                        <td class="ProjectCardData">
                            <asp:TextBox ID="txtEndingDate" runat="server" Columns="10" MaxLength="10" 
                                style="background-image: url('images/png/calendarpicker_18x18.png'); background-repeat: no-repeat; background-position: right center;" 
                                TabIndex="16"></asp:TextBox>
                        </td>

Open in new window


I use a web service from Dynamics to create a new record. The creation date and modified date are stored correctly into the database.

protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            ReadSession();
        }
        else
        {
            //we clear what might be left
            Session.RemoveAll();
            Session.Clear();

            // Set default date for starting & ending date
            txtStartingDate.Text = DateTime.UtcNow.ToShortDateString();
            txtEndingDate.Text = DateTime.UtcNow.ToShortDateString();
        }
    }

protected bool SubmitThisProjectToNavision()
    {
        //new General().SetThreadToDutch();

        string returnVal = "";
        bool hasSuccess = false;
        //string CustomerName = "";
        int NumberOfItems = ProjectList.Rows.Count;

        // Create an instance of ProjectCard.
        ProjectCard newProjectCard = new ProjectCard();
        // Create an instance of the service and set credentials.
        ProjectCard_Service ProjectCardServ = new ProjectCard_Service();
        try
        {
            ProjectCardServ.UseDefaultCredentials = true;

            DateTime startDate = DateTime.Parse(txtStartingDate.Text.ToString());
            DateTime endDate = DateTime.Parse(txtEndingDate.Text.ToString());
            
            // Insert project
             newProjectCard.Last_Date_Modified = DateTime.UtcNow;
            newProjectCard.Creation_Date = DateTime.UtcNow;
            newProjectCard.Starting_Date = DateTime.Parse(txtStartingDate.Text);
            newProjectCard.Ending_Date = endDate;
            ProjectCardServ.Create(ref newProjectCard);

            hasSuccess = true;
        }
        catch (Exception exep)
        {
            hasSuccess = false;

            try { ProjectCardServ.Delete(newProjectCard.Key); }
            catch (Exception) { }
        }

        if (hasSuccess)
        {
            returnVal = newProjectCard.No;
        }

        return hasSuccess;
    }

Open in new window


Can anyone help me to store the date correctly into the database.


Thanks,
Maarten
0
Comment
Question by:maartendierckxsens
[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
  • 6
  • 2
8 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34218724
Can you send me database intarction code(.Create method) and ReadSession() code.

0
 

Author Comment

by:maartendierckxsens
ID: 34222797
when the user clicks on the ok button, a new record will be aded.

What do you mean by db interaction code?
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34225939
Where are you storing the records in DB or File system. I asked how do you written code to interact the DB(insert command to save the record).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:maartendierckxsens
ID: 34226653
it is stored in a database.

the record is created through a web service of Microsoft Dynamics NAV.
0
 

Author Comment

by:maartendierckxsens
ID: 34228258
the web service does an insert statement
0
 

Author Comment

by:maartendierckxsens
ID: 34333993
i managed to solve the problem
0
 

Accepted Solution

by:
maartendierckxsens earned 0 total points
ID: 34334014
solved by doing the following:

1

create the record with the unique no.

2

after creation do an update
newProjectCard.No = txtNo.Text.ToString();
ProjectCardServ.Create(ref newProjectCard);

newProjectCard.Starting_Date = DateTime.Parse(txtStartingDate.Text, System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
newProjectCard.Ending_Date = DateTime.Parse(txtEndingDate.Text, System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);

ProjectCardServ.Update(ref newProjectCard);

Open in new window

0
 

Author Closing Comment

by:maartendierckxsens
ID: 34383926
it wasn't that difficult after all, in fact quiet easy
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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