如何在数据库中插入日期n时间 [英] how to insert a date n time in database

查看:83
本文介绍了如何在数据库中插入日期n时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它给我一个语法错误

it is giving me a syntax error

con.Open();
OleDbCommand cmd =
    new OleDbCommand(
        "insert into coupen(voucher,RS,Date) values('" + _voucher + "','" + TxtAmount.Text + "',GetDate())", con);
int result = cmd.ExecuteNonQuery();
con.Close();

推荐答案

试试这个:

Try this:
con.Open();
OleDbCommand cmd =
    new OleDbCommand(
        "insert into coupen(voucher,RS,[Date]) values('" + _password + "','" + TxtAmount.Text + "',"+ DateTime.Now.Date + ")", con);
int result = cmd.ExecuteNonQuery();
con.Close();


getdate()是使用oledb不会执行的sql函数。而且,还有一点是你无法使用ado.net从codebehind发送getdate()。



更改查询,





getdate() is the sql function it will not execute using oledb. And, one more point is you cannot send getdate() from codebehind using ado.net.

change the query,


con.Open();
OleDbCommand cmd =
    new OleDbCommand(
        "insert into coupen([voucher],[RS],[Date]) values('" + _password + "','" + TxtAmount.Text + "','"+ System.DateTime.Now + "')", con);
int result = cmd.ExecuteNonQuery();
con.Close();





试试这个。

如果发生错误粘贴错误发生。



try this.
if error occurs paste the error occuring.


试试这个:

Try this:
con.Open();
OleDbCommand cmd = new OleDbCommand("INSERT INTO COUPEN(voucher,RS,Date) VALUES ('" + _password + "','" + txt.Text + "','" + DateTime.Now + "')", con);
int result = cmd.ExecuteNonQuery();
con.Close();





尝试交叉检查您的表/列名称一次。



--Amit



Try to crosscheck your table/column name once.

--Amit


这篇关于如何在数据库中插入日期n时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆