Hello,
I have a program that use ACCESS as database.
In my database i have a table ho have same row set to:
Date/Time with no format in the database.
I want to save a
date and time in my database from a datatimepicker.
When a retrieve from my datatimepicker the value, it save in my database only the date, but i need and time.
If i use
DateTime saveDate = DateTime.Now;
This is the cod to save in my database.
private void btnAdaugaContract_Click(object sender, EventArgs e)
{
VerificareDateIntroduse();
if (DateIntroduse == true)
{
try
{
Program.Connection.CommandText = "INSERT INTO Contracts (ContractId, ClientId, CreateDate, StartDate, EndDate, Procent) values (@ContractId, @ClientId, @CreateDate, @StartDate, @EndDate, @Procent)";
Program.Connection.AddParameter("@ContractId", txtNumarContract.Text);
Program.Connection.AddParameter("@ClientId", ClientActiv.ClientID);
Program.Connection.AddParameter("@CreateDate", Convert.ToDateTime(dInceput.Value));
Program.Connection.AddParameter("@StartDate", Convert.ToDateTime(dInceput.Value));
Program.Connection.AddParameter("@EndDate", Convert.ToDateTime(dFinalizare.Value));
Program.Connection.AddParameter("@Procent", Convert.ToDouble(txtComision.Text.Replace('.', ',')));
Program.Connection.ExecuteNonQuery();
for (int i = 0; i < dataProduseAmanet.Rows.Count; i++)
{
Program.Connection.CommandText = "INSERT INTO ContractItems (ContractId, Name, Description, Payment, Quantity, QuantityUnit) values (@ContractId, @Name, @Description, @Payment, @Quantity, @QuantityUnit)";
Program.Connection.AddParameter("@ContractId", txtNumarContract.Text);
Program.Connection.AddParameter("@Name", dataProduseAmanet.Rows[i].Cells[0].Value.ToString());
Program.Connection.AddParameter("@Description", dataProduseAmanet.Rows[i].Cells[3].Value.ToString());
Program.Connection.AddParameter("@Payment", dataProduseAmanet.Rows[i].Cells[1].Value.ToString());
Program.Connection.AddParameter("@Quantity", dataProduseAmanet.Rows[i].Cells[2].Value.ToString());
Program.Connection.AddParameter("@QuantityUnit", dataProduseAmanet.Rows[i].Cells[4].Value.ToString());
Program.Connection.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.Close();
}
}
if i replace the
Program.Connection.AddParameter("@CreateDate", Convert.ToDateTime(dInceput.Value));
with
Program.Connection.AddParameter("@CreateDate", saveDate);
the
dInceput
is the datatimepicker with no formating.
The
saveDate have the date and time, but it gives me the error: "data type mismatch".
Some suggestions.
Tanks.