I have two forms ("entry" and "reservation").
I have one database with have two columns ("datereservation" and "names").
In opening the "entry" form if there is any reservation date today, the "reservation" form should open automatically. In other case its couldnot.
Please have a look on my codes:
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\hotel\hotel\\app_data\reservation.mdb;Persist Security Info=False";
OleDbConnection sqlCon = new OleDbConnection(connectionString);
sqlCon.Open();
string commandString = "select * from reservation where datereservation ='" + DateTime.Now + "'";
OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
OleDbDataReader read = sqlCmd.ExecuteReader();
{
MessageBox.Show("There is no reservation " + DateTime.Now + " encontrada(s)");
}
read.Close();
sqlCon.Close();
RptReservation reserv = new RptReservation ();
reserv.ShowDialog();
VulpesPosted Nov 25, 2014, 4:29 PM
sqlCon.Close();
Mfwamba TshimangaPosted Nov 25, 2014, 2:58 PM
@Vulpes
See what I do and its gives this error "Type of datas incorrect in expression query". But I went in msaccess database and I put my column data as date/hour and dd-mm-yyyy
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\hotel\hotel\\app_data\reservation.mdb;Persist Security Info=False";
OleDbConnection sqlCon = new OleDbConnection(connectionString);
sqlCon.Open();
string commandString = "select * from reservation where datereservation ='" + DateTime.Today+ "'";
OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
OleDbDataReader read = sqlCmd.ExecuteReader();
{
MessageBox.Show("There is no reservation " + DateTime.Today + " encontrada(s)");
}
read.Close();
sqlCon.Close();
VulpesPosted Nov 24, 2014, 10:34 AM
If only the date of the reservation is stored in the database and you want to get all reservations for today then I'd use DateTime.Today instead.
You might also have a problem with the formatting of the date. If you are, then I'd try:
DateTime.Today.ToString("yyyy-MM-dd")