将DateTime插入Sql数据库 [英] Insert DateTime to Sql Database

查看:89
本文介绍了将DateTime插入Sql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有


我希望您能帮助将日期时间插入和更新到SQL数据库。


请帮助。


谢谢

解决方案

你好


你可以照常使用普通的sql查询其他领域如何插入,


你试过吗,你有没有收到任何错误,


大多数情况下你会得到格式转换错误,默认情况下,sqlserver将采用 MM / dd / yyyy 格式,确保您的输入采用其他格式,您可以使用现有的转换函数将其转换为自定义格式。

你知道如何插入/更新日期时间以外的东西吗?我想在这里得到的是:你是否有一个专门针对日期时间的问题,或者你只是不知道如何在你的程序中使用数据库?我们有一些关于如何使用数据库的文章。我建议你在Howto部分查看它们。否则,如果是日期时间问题,您可以使用参数化查询而不必担心它。


这是使用参数化查询的代码示例:

展开 | 选择 | Wrap | 行号


亲爱的所有


感谢您的帮助,但我需要如下:

我添加DateTimePicker,我想插入像

strSQL =" INSERT INTO tblBooking(bPNR,bPaxName,bIssureDate,bTravelDate,bDeparting,bArriving,bFlyType,bStatus,bBy ,bNetPrice,bSalePrice)" &安培; VALUES(''"& txtPNR.Text&"'',''"& txtPaxName.Text&"'',''"& DateTimePicker1.Text&"' ',''"& DateTimePicker2.Text&"'',''"& txtDeparting.Text&"'',''"& txtArriving.Text&"'', ''"& cboFlyType.Text&"'',''"& cboStatus.Text&"'',''"& cboBy.Text&"''," & txtNetPrice.Text&","& txtSalePrice.Text&")"


请指教


感谢

Dear All

I would like you to help to insert and update datetime to sql database.

Please kindly help.

thanks

解决方案

Hello

you can use normal sql query as usual like other fields how you are inserting ,

have you tried it ,did you get any error,

mostly you will get format conversion errors ,by default sqlserver will take MM/dd/yyyy format ,make sure that your input is in that format other you can conver that to your custom format with the existing convert functions.


Do you know how to insert/update things other than datetimes? What I''m trying to get at here is: do you have a problem specifically with datetimes, or do you just not know how to use a DB in your program? We have a few articles on how to use databases. I''d suggest you check them out in the Howto section. Otherwise, if it is a datetime problem, you can use a parameterized query and not have to worry about it.

Here''s a code sample on using a parameterized query:

Expand|Select|Wrap|Line Numbers


Dear All

thank you for your help, but I need as bellow:
I add DateTimePicker and i want to insert like
strSQL = "INSERT INTO tblBooking(bPNR, bPaxName, bIssureDate, bTravelDate, bDeparting, bArriving, bFlyType, bStatus, bBy, bNetPrice, bSalePrice)" & "VALUES(''" & txtPNR.Text & "'', ''" & txtPaxName.Text & "'',''" & DateTimePicker1.Text & "'',''" & DateTimePicker2.Text & "'',''" & txtDeparting.Text & "'',''" & txtArriving.Text & "'',''" & cboFlyType.Text & "'',''" & cboStatus.Text & "'',''" & cboBy.Text & "''," & txtNetPrice.Text & "," & txtSalePrice.Text & ")"

please advise

thanks


这篇关于将DateTime插入Sql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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