Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to save the date entered in textbox to database?

Posted on 2010-11-26
8
Medium Priority
?
682 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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