1

I am currently working in windows form application in visual studio express for desktop. I also have an sql back end. I am trying to pull a smalldatetime from a DGV that has been loaded from an SQL table and then move it into a textbox on a new form. Right now the date format is MM/dd/yyyy HH:mm:ss. I need the datetime to be in the format yyyy-MM-dd HH:mm:ss. Here is my code:-

Try

      Dim f As New frmCuttingMachineCutList

      If e.ColumnIndex = 1 Then
        Dim Row_Index As Integer = DGVFinish.CurrentCell.RowIndex
        MsgBox(DGVFinish.Rows(Row_Index).Cells(5).Value)
        f.txtshear.Text = DGVFinish.Rows(Row_Index).Cells(5).ToString("yyyy-MM-dd HH:mm:ss")
        f.lblshear.Text = DGVFinish.Rows(Row_Index).Cells(1).Value

        End If


        f.Show()

    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
Filburt
  • 17,626
  • 12
  • 64
  • 115
Cheddar
  • 530
  • 4
  • 30
  • 1
    What's the question? – rheitzman Aug 06 '15 at 16:29
  • I am getting an error that reads conversion from string "yyyy-MM-dd HH:mm:ss to type integer is not valid -----> system.formatexception:Input String was not in a correct format. I dont see why it is trying to reformat the string into an integer. – Cheddar Aug 06 '15 at 17:29

1 Answers1

1

you may need to convert your cell's value to a DateTime before being able to format it. Try

Dim date as DateTime = DGVFinish.Rows(Row_Index).Cells(5).Value as DateTime;
f.txtshear.Text = date.ToString("yyyy-MM-dd HH:mm:ss");
psoshmo
  • 1,490
  • 10
  • 19