Atul Rokade

Atul Rokade

  • NA
  • 141
  • 42.2k

how to insert current date into access database?

Jul 25 2016 12:53 PM
Actually im creating one application where i inserted user sales count, sales count is updating fine but when i edit in query by putting current date its not updating detail Here im putting whole code
 
Private void button1_Click_1(object sender, EventArgs e)
{
this.txtinput.MaxLength = 4;
cmd = new OleDbCommand("update Login set Sales_count= IIF(IsNull(Sales_count), 0, Sales_count) + 1 where [Unique_No]=@Unique_No and [To_Date]='#"+DateTime.Now.ToString("dd/MM/yyyy")+"#'", con);
cmd.Parameters.AddWithValue("@Unique_No", txtinput.Text);
con.Open();
int n = cmd.ExecuteNonQuery();
if (n == 0)
{
MessageBox.Show("Invalid Unique No. pls try again later");// **Debugger come to this line if i insert [To_Date]='#"+DateTime.Now.ToString("dd/MM/yyyy")+"#'** // if i remove above line in code then its updating fine
}
else
{
this.DialogResult = DialogResult.OK;
}
con.Close();
}
}
 

Answers (5)