473,329 Members | 1,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,329 software developers and data experts.

Insert DateTime to Sql Database

Kosal
68
Dear All

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

Please kindly help.

thanks
Jul 16 '08 #1
13 4876
nmsreddi
366 256MB
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.
Jul 16 '08 #2
Curtis Rutland
3,256 Expert 2GB
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
  1. //c# code.
  2. //dt is the datetime field
  3. string update = "update test set dt=@dt where id=@id";
  4. OleDbCommand cmd = new OleDbCommand(update, conn);
  5. DateTime dtme = DateTime.Now;
  6. cmd.Parameters.AddWithValue("@dt", dtme.ToString());
  7. cmd.Parameters.AddWithValue("@id", Convert.ToInt32(TextBox2.Text));
  8.  
Then you just execute the query as you normally would.
Jul 16 '08 #3
Kosal
68
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
Jul 17 '08 #4
Curtis Rutland
3,256 Expert 2GB
Well, if you'll read my reply, I show you how to use a parameterized query. That's the easiest way to do this. Change your values clause to "VALUES (@bPNR, @bPaxName, @bIssureDate ... " and so forth. Then add the parameter values. My example was in C#, but it shouldn't be that hard to translate to vb.
Jul 17 '08 #5
Kosal
68
ok thank you for your advise i will try to do it.
thanks
Jul 17 '08 #6
Kosal
68
Dear all

I try to do it but still error can you give me the full code for this problem in vb.net

I am waiting for your advise

thanks
Best Regard
Jul 17 '08 #7
Curtis Rutland
3,256 Expert 2GB
We don't do your assignment for you here. Please don't ask for a full code solution.

MODERATOR

Now, if you post what you've tried and the error message, we can get down to business trying to help you correct your code.
Jul 17 '08 #8
Kosal
68
ok thanks you for your help, but i still cannot do anything yet with
insert datetimepicker to database.

thanks
Jul 17 '08 #9
Curtis Rutland
3,256 Expert 2GB
If you tell us what error message you get, we might actually be able to help you.
Jul 17 '08 #10
hi Kosal,
datepicker1.value instead of datepicker1.text , it is working in VB.net 2003
with sql server
Try it out...

ganesh
Jul 20 '08 #11
Kosal
68
Hi All
thank you for your help
now I resolve this problem already.

thanks
Jul 22 '08 #12
HI,

You can store in one variable like = datatime.now (This is vill give current datatime.then you can pass to database.

Otherwise change the format like "DD/MM/YYYY"
Aug 13 '08 #13
Kosal
68
Ok Sir

Now it is ok
Thank you for you advice

thank
Best Regard
Sep 8 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: chuayongquan | last post by:
How do i insert this string "23:58:44.000 UTC Wed May 11 2005" into the database with datetime data format... I tried using: insert into table (startime) values ('23:58:44.000 UTC Wed May 11...
1
by: aish | last post by:
I want to insert datetime into the database.I want to insert date as a dd/MMMM/yyyy format SqlDateTime x; if((TextBox1.Text).Length==0) { x=SqlDateTime.Null; } else {...
1
by: Lam | last post by:
hi Does anyone know how to insert Date to SQL server 2000? I used DataTime.Today.ToShortDateString() it shows up "1/1/1900" in the database how can I correct that? also, how can I pull out the...
1
by: thomas kern | last post by:
hi, i tried to insert a record into a mssql-table. one column is DateTime. i tried this one: insert into fixtures (dategame) VALUES ('24.01.2003') unfortunately i receive an error -- error...
2
by: ven | last post by:
Hello i have two tables in my MS SQL named table1 and table2. In each table i have a column PRICE with my own datatype decimal 14;4 allows nulls.... now i wanna select from one table to second...
6
by: Frederik Vanderhaeghe | last post by:
Yo, I have a problem inserting into my database. When i try the following: "INSERT INTO TBL_Bestanden_Zoeken (Id,docnr,klnr,klnaam,datum,bedrag,type) VALUES...
3
by: Bon | last post by:
Dear all How can I convert a datetime in Short Date format to General Date format and then insert into SQL database? I get a date from a field using Request("in_date"), which is in Short...
4
by: Arpan | last post by:
A SQL Server 2005 DB table has 4 columns namely "ID" (IDENTITY int column), "FirstName" (varchar(50)), "LastName" (varchar(50)) & "DOB" (datetime). Now when I am trying to add a new row using the...
5
by: Steve Kershaw | last post by:
Hi I have a problem in that I need to save the creation date of a new record to a column. The column is set up as a datetime type and the C# date is a DateTime type. I keep on getting an error that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.