The Artima Developer Community
Sponsored Link

C# Answers Forum
Insert a datetime into MS Access

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Hani Ramdan

Posts: 2
Nickname: alsheehab
Registered: Dec, 2008

Insert a datetime into MS Access Posted: Dec 4, 2008 1:36 PM
Reply to this message Reply
Advertisement
Hi
My first time with C#

I faced a problem that i couldn't insert a datetime from datetimepicker into MS Access column with datetime data type although i managed to insert a text from textbox.
Please can any body help me?




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Sample
{
public partial class Form1 : Form
{
OleDbConnection conn;
OleDbCommand comm;
OleDbDataAdapter Adapt;
DataTable dat;
DataSet ds;
DataRow newrow;


private void bt1_Click(object sender, EventArgs e)
{


try
{
conn = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=D:\budjety\author.mdb;Persist Security Info=False");
conn.Open();
comm = new OleDbCommand("SELECT * from author",conn);
Adapt = new OleDbDataAdapter();
Adapt.SelectCommand = comm;
OleDbCommandBuilder cb = new OleDbCommandBuilder(Adapt);

ds = new DataSet("author");
Adapt.Fill(ds, "author");
dat = ds.Tables[0];
newrow = ds.Tables["author"].NewRow();

newrow.BeginEdit();
newrow["Date"] = dateTimePicker1.Text;
newrow["Transportation"] = t1.Text;
newrow["Groceries"] = t2.Text;
newrow["Fruniture"] = t3.Text;
newrow["Phone"] = t4.Text;
newrow["Bill_Water"] = t5.Text;
newrow["Bill_Electr"] = t6.Text;
newrow["Medical"] = (t7.Text);
newrow["Kat"] = (t8.Text);
newrow["Clothes"] = (t9.Text);
newrow["Family"] = (t10.Text);
newrow["Community"] = (t11.Text);
newrow["Gifts"] = (t12.Text);
newrow["Advance"] = (t13.Text);
newrow["Other"] = (t14.Text);
newrow.EndEdit();

ds.Tables["author"].Rows.Add(newrow);
Adapt.Update(dat);
ds.AcceptChanges();



conn.Close();
}
catch (OleDbException e)
{

MessageBox.Show(e.ToString());

}


}
}
}

Topic: C# and Delphi Previous Topic   Next Topic Topic: how can detect encoding in c#

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use