?
Solved

How to save the date entered in textbox to database?

Posted on 2010-11-26
8
Medium Priority
?
681 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
Industry Leaders: 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

800 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