I would like to ask for your help about my datetimepicker
. I can't insert date to my firebird database, my firebird version is 2.5.4
. my DATE
in firebird has datatype of DATE
; I've also tried TIMESTAMP
.
This is my code:
private void button1_Click(object sender, EventArgs e)
{
FbConnection con = new FbConnection(BackEndCode.clKoneksyon.DbCon());
FbCommand cmd = new FbCommand("INSERT INTO TBLLAN_SETUP (DATE) VALUES (@DATE)", con);
cmd.Parameters.AddWithValue("@DATE", dtpDate.Value.Date.ToShortDateString());
con.Open();
cmd.ExecuteNonQuery();
con.Dispose();
con.Close();
cmd.Dispose();
}
i also try this with no luck
cmd.Parameters.AddWithValue("@DATE", dtpDate.Value.Date);
This is the error I got
An unhandled exception of type 'FirebirdSql.Data.FirebirdClient.FbException' occurred in FirebirdSql.Data.FirebirdClient.dll
EDIT: Updated code with exception handling
private void button1_Click(object sender, EventArgs e)
{
FbConnection con = new FbConnection(BackEndCode.clKoneksyon.DbCon());
FbCommand cmd = new FbCommand("INSERT INTO TBLLAN_SETUP (DATE) VALUES (@DATE)", con);
cmd.Parameters.AddWithValue("@DATE", dtpDate.Value.Date);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Dispose();
con.Close();
cmd.Dispose();
}
}
DATE是保留字,因此请尝试:
"INSERT INTO TBLLAN_SETUP ([DATE]) VALUES (@DATE)"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.