🔒 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
  • 450
    Views
  • 2
    Participants
Last reply from:
daosjohnpeter05

Trending Topics

Online now

Members online
464
Guests online
968
Total visitors
1,432

Forum statistics

Threads
2,286,945
Posts
29,041,378
Members
1,217,282
Latest member
Andreew00012
Back
Top