🔒 Closed Need help in SQL Query and conversion of datatypes VB.Net

Status
Not open for further replies.

daosjohnpeter05

Enthusiast
Hello mga ka PHC, meron ako prob sa ginagawa kong project. Sa SQL query at sa datatypes. Yung column ko kasi sa database ay may datatype na "time (7)", gusto ko i insert yung string value ng timeLbl.Text sa database kasabay ng data ng employee, kaso ang nagiging problema ko palagi ay invalid conversion of datetime from string.

Ginawa ko na yung sa conversion ng variable gamit ang sql parameters pero wala pa din, eto ang buong code ko ..Pasensya na bago lang ako sa MSSQL, thanks ^_^

Private Sub timeIn()

Try
connection = New SqlConnection(constr)
command = connection.CreateCommand
command.CommandText = "INSERT INTO Clocks (employeeID, firstName, middleName, lastName, position, dateIn, timeIn) VALUES ('" & idTxt.Text & "', '" & firstnameTxt.Text & "', '" & middlenameTxt.Text & "', '" & lastnameTxt.Text & "', '" & positionTxt.Text & "', '" & dateIn & "', '" & Convert.ToDateTime(timeLbl.Text) & "')"
connection.Open()

command.ExecuteReader()


Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
 
Solution
It's either empty yung textbox or di pwedi e-covert sa date yung data ng textbox. Kung mag-insert ka ng time bakit di mo kunin yung time ng current machine using DateTime.Now.ToString("hh:mm:ss")?
yung value ng timeLbl.Text is nasa loob ng timer1 ko which is nagbabago every second. try ko din to idol ..

EDIT:

Nagra run na yung function ^_^ mali lang yung data type ng variable ko which is "dateIn"
It's either empty yung textbox or di pwedi e-covert sa date yung data ng textbox. Kung mag-insert ka ng time bakit di mo kunin yung time ng current machine using DateTime.Now.ToString("hh:mm:ss")?
yung value ng timeLbl.Text is nasa loob ng timer1 ko which is nagbabago every second. try ko din to idol ..

EDIT:

Nagra run na yung function ^_^ mali lang yung data type ng variable ko which is "dateIn"
 
Solution
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 446
    Views
  • 2
    Participants
Last reply from:
daosjohnpeter05

Online now

Members online
1,025
Guests online
869
Total visitors
1,894

Forum statistics

Threads
2,276,231
Posts
28,968,504
Members
1,231,175
Latest member
cflakashi
Back
Top