simon taylor

simon taylor

  • NA
  • 38
  • 69.1k

trouble inserting dattime in ms access

Jan 2 2011 9:42 AM

Hi,
i have created a 'Project' form which allows the user to enter details for a new project e.g name, starte and end date of the prject ect. The problem i am having right now is that when insert all my values including the start and end date of the prjoect, when i look in my ms access db, all my other values are successfully stored in 'Project2' table like the name of the project  BUT the start and end dates do not appear, but only seen as '#######'. Why is this occuring? When i look in the design view, the data types are set to Date/Time for both columns Start Date and End Date.
namespace AddProject_V2
{
  public partial class AddProjectfrm : Form
  {
    private string projectName;
    private string startDate;
    private string endDate;

 // AddProjectfrm initializes the instance variables for each project based on user input
    public AddProjectfrm()
    {
      InitializeComponent();
      setProject(); 
      conDB();
      setWeeks();
     
    }

// setProject function sets the name, targets and job starts 
    public void setProject()
    {
this.projectName = projectNametxtbx.Text;
      target1Day = Convert.ToInt32(target1daytxtbx.Text);
      target2Day = Convert.ToInt32(target2daytxtbx.Text);
 startDate = startDatetimepcker.Value.ToString();
      endDate = endDatetimepcker.Value.ToString();
           }

private void submittbtn_Click(object sender, EventArgs e)
    {
      conDB();
      setProject();
 

      totalTarget += target1Day + target2Day + target5Day + target10Day + target15Day;

      insertCommand = "INSERT into Project2(projectName, startDate, endDate, duration, targetOne, targetTwo, targetFive, targetTen, targetFifteen, targetTotal, totalWeeks, jobStarts)" +
        "VALUES" + "("+"'"+this.projectName+"'"+"," + "'" + startDate+"'"+","+"'"+endDate+"'"+","+"5"+","+this.target1Day+"," + this.target2Day+","+target5Day+","+target10Day+","+target15Day+ ","
        +totalTarget+","+"2"+","+this.jobStarts+")";

oldbCommand = new OleDbCommand(insertCommand, oldbCon);
        
        
        oldbAdapter = new OleDbDataAdapter(oldbCommand);
        dataSet = new DataSet();
        oldbAdapter.Fill(dataSet, "Project2");
}

have i done my conversion wrong?

Answers (1)