0

Hello, I have one DateTimePicker and two textbox (txtHour and txtMinute)
I want insert the value of datetimepicker (date) and textbox (hour and minute from two different textbox) to DateTime data type on my table, example: 2013-08-28 12:30:00 PM --> the value of 12 got from txtHour, the value of 30 got from txtMinute
How to do that?
Thanks

Edited by lwin

2
Contributors
5
Replies
27
Views
4 Years
Discussion Span
Last Post by Hazuan Nazri
0

you can try like this, if i wrong please inform me

Dim dr As DataRow = DBDataSet.Tables("Table").NewRow
                    cmdIn1 = conn.CreateCommand
                    cmdIn1.CommandText = "INSERT INTO Table(Name, Sex, DateTime)VALUES('" & Trim(Name.Text) & "','" & Trim(Sex.Text) & "','" & Trim(DateTimePicker.Value) & "')"
                    check = cmdIn1.ExecuteReader.RecordsAffected()
                    If check > 0 Then
                        MsgBox("Data " & Trim(Name.Text) & " save successfull", MsgBoxStyle.OkOnly, "Message :")
                        DBDataSet.AcceptChanges()

please vote me if i already fix your problem, or ask me if you got problem.
Thank You!!

Edited by Hazuan Nazri

0

not like that,
this is my code :

Dim wm As String = txtJamM.Text + txtMenitM.Text + "00"
Dim ws As String = txtJamS.Text + txtMenitS.Text + "00"
Dim tampWM As String = dtpWM.Value.ToString("yyyyMMdd") + wm
Dim tampWS As String = dtpWS.Value.ToString("yyyyMMdd") + ws
Dim dtWM = DateTime.ParseExact(tampWM, "yyyyMMddHHmmss", Nothing)
Dim dtWS = DateTime.ParseExact(tampWS, "yyyyMMddHHmmss", Nothing)
MsgBox(dtWM + " & " + dtWS)
sql = "update detailjadwal set waktumulai='" + dtWM + "',waktuakhir='" + dtWS + "' where kodedetail='" + lbKodeDetail.Text + "'"

but that code generate 0000-00-00 00:00:00 in my database table on DateTime column

0

Nice job Iwin....for easy code, you can only insert the datetimepicker.value and it will save your date and time for column type = datetime.

0

I already know that, but datetimepicker.value generates timestamp (time from PC), not the time from user input in textbox.
I've solved my problem,
Here is the right code:

Dim wm As String = txtJamM.Text + txtMenitM.Text + "00"
Dim ws As String = txtJamS.Text + txtMenitS.Text + "00"
Dim tampWM As String = dtpWM.Value.ToString("yyyyMMdd") + wm
Dim tampWS As String = dtpWS.Value.ToString("yyyyMMdd") + ws
Dim thn As String = tampWM.ToCharArray(0, 4)
Dim bln As String = tampWM.ToCharArray(4, 2)
Dim hari As String = tampWM.ToCharArray(6, 2)
Dim jam As String = tampWM.ToCharArray(8, 2)
Dim mnt As String = tampWM.ToCharArray(10, 2)
Dim dtk As String = tampWM.ToCharArray(12, 2)
Dim tanggal As String = thn + "-" + bln + "-" + hari + " " + jam + ":" + mnt + ":" + dtk

sql = "update detailjadwal set waktumulai='" + tanggal + "' where kodedetail='" + lbKodeDetail.Text + "'"

:D anyway, thanks for your response

0

oh! ok....i understand now, hour and minutes textbox is manually insert by user right? nvm, dont forget to mark as solve your question....Thank You!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.