I need to save in my database from my datetimepicker only the MONTH and YEAR. But its doesnt works.
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();
}