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
Solved

How to save the date entered in textbox to database?

Posted on 2010-11-26
8
676 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
tableview is not updating 1 20
RegEx with optional part 4 42
Finding Events logs for IIS website that restarts 2 14
Input parameteres to DragOver 2 19
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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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