C# and MS-Access : Inserting or updating datetime
-
Hi all, I have a C# desktop application and I am using MS-Access database. I am using below code for update operation. string SqlString = "UPDATE table_name SET Bdate = @Bdate WHERE SrNo = @SrNo"; OledbCmd = new OleDbCommand(SqlString, OleDbConn); OledbCmd.Parameters.AddWithValue("@SrNo", intSrNo); OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString()); Same approach is used for Insert operation also. All working fine... But I have read in one article that, DateTime should be enclosed withing single quote or #, when you are working with MS-Access. Right now, my code is working fine. Please, explain me if there is any difference between the approach I am using and the approach that I have read.. Thanks,
Regards, -SIFAR.
-
Hi all, I have a C# desktop application and I am using MS-Access database. I am using below code for update operation. string SqlString = "UPDATE table_name SET Bdate = @Bdate WHERE SrNo = @SrNo"; OledbCmd = new OleDbCommand(SqlString, OleDbConn); OledbCmd.Parameters.AddWithValue("@SrNo", intSrNo); OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString()); Same approach is used for Insert operation also. All working fine... But I have read in one article that, DateTime should be enclosed withing single quote or #, when you are working with MS-Access. Right now, my code is working fine. Please, explain me if there is any difference between the approach I am using and the approach that I have read.. Thanks,
Regards, -SIFAR.
-
Hi all, I have a C# desktop application and I am using MS-Access database. I am using below code for update operation. string SqlString = "UPDATE table_name SET Bdate = @Bdate WHERE SrNo = @SrNo"; OledbCmd = new OleDbCommand(SqlString, OleDbConn); OledbCmd.Parameters.AddWithValue("@SrNo", intSrNo); OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString()); Same approach is used for Insert operation also. All working fine... But I have read in one article that, DateTime should be enclosed withing single quote or #, when you are working with MS-Access. Right now, my code is working fine. Please, explain me if there is any difference between the approach I am using and the approach that I have read.. Thanks,
Regards, -SIFAR.
If Bdate is a date then don't call ToSTring() when setting the parameter
OledbCmd.Parameters.AddWithValue("@Bdate", DateTime.Now.ToString());