What's new

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

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
 
Last edited:
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")?
 
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"
 
Last edited:
Solution

Similar threads

Back
Top