Israel

Israel

  • 705
  • 1.3k
  • 216.4k

How to save ONLY month and year in MSAccess database

Aug 5 2015 8:12 AM
Hi!
 
I need to save in my database from my datetimepicker only the MONTH and YEAR. But its doesnt works.
Then see what I do and help me to resolv my problem please:
 
conn = new OleDbConnection(connstr);
comm = new OleDbCommand();
conn.Open();
OleDbParameter name = new OleDbParameter("@name", SqlDbType.VarChar);
OleDbParameter monthyear = new OleDbParameter("@monthyear", SqlDbType.VarChar);
comm.Parameters.Add(name);
comm.Parameters.Add(monthyear);
 
name.Value = txtName.Text;
monthyear .Value = txtMonthYear.Text;
comm.Connection = conn;
comm.CommandText = "insert into DBTest ([name],[monthyear]) values(@name,@monthyear)";
if(MessageBox.Show("Are you sure to save?","Windows for Save",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved...");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}

Answers (8)