Solved

How to save the date entered in textbox to database?

Posted on 2010-11-26
8
673 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
  • 6
  • 2
8 Comments
 
LVL 12

Expert Comment

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

0
 

Author Comment

by:maartendierckxsens
Comment Utility
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
Comment Utility
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
 

Author Comment

by:maartendierckxsens
Comment Utility
it is stored in a database.

the record is created through a web service of Microsoft Dynamics NAV.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:maartendierckxsens
Comment Utility
the web service does an insert statement
0
 

Author Comment

by:maartendierckxsens
Comment Utility
i managed to solve the problem
0
 

Accepted Solution

by:
maartendierckxsens earned 0 total points
Comment Utility
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
Comment Utility
it wasn't that difficult after all, in fact quiet easy
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How do I get the unique ID after insert? 87 87
.NET Error 7 40
Re-position sub-options beneath the TAB 7 36
Problem to page 4 16
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now