'Transfer Date from DataGridView to Crystal Reports VB.NET

When I use these codes Dim inDate As String = CStr(dgr.Cells(0).Value.ToString("MM-dd-yyyy")). The error says the conversion from string "MM-dd-yyyy" to type integer is not valid. But when I use these codes Dim inDate As String = CStr(dgr.Cells(0).Value. It displays the date from GridView but with a time format. I only want to display the date, not the datetime. To transfer data from grid view to crystal reports. I used DataSet and DataTable. The data type of date columns from the table is a string. These are my full code.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim report1 As New payslip
        Try
            Dim ds As New DataSet1
            Dim ms As New MemoryStream
            CompanyLogo_Picture.Image.Save(ms, CompanyLogo_Picture.Image.RawFormat)
            Dim byt() As Byte = ms.ToArray
            ds.DataTable1.Rows.Add(byt)
            For Each dgr As DataGridViewRow In DataGridView3.Rows
                Dim inDate As String = CStr(dgr.Cells(0).Value.ToString("MM-dd-yyyy"))
                Dim inTime As TimeSpan = dgr.Cells(1).Value
                Dim outDate As String = CStr(dgr.Cells(2).Value.ToString("MM-dd-yyyy"))
                Dim outTime As TimeSpan = dgr.Cells(3).Value
                ds.DataTable2.Rows.Add(inDate, inTime, outDate, outTime)
            Next
            report1.SetDataSource(ds)
            report1.SetParameterValue("employeeName", TextBox6.Text)
            report1.SetParameterValue("companyName", CompanyName_Label.Text)
            report1.SetParameterValue("companyAddress", CompanyAddress_Label.Text)
            report1.SetParameterValue("dateFrom", DateTimePicker1.Text)
            report1.SetParameterValue("dateTo", DateTimePicker2.Text)
            report1.SetParameterValue("dailyRate", payslip_dailyRate.Text)
            report1.SetParameterValue("totalDays", payslip_totalDays.Text)
            report1.SetParameterValue("mealAllowance", payslip_mealAllowance.Text)
            report1.SetParameterValue("transportationAllowance", payslip_transpoAllowance.Text)
            report1.SetParameterValue("medicalAllowance", payslip_medicalAllowance.Text)
            report1.SetParameterValue("grossPay", payslip_grossPay.Text)
            report1.SetParameterValue("SSS", payslip_sss.Text)
            report1.SetParameterValue("philHealth", payslip_philhealth.Text)
            report1.SetParameterValue("pagibig", payslip_pagibig.Text)
            report1.SetParameterValue("loans", payslip_loans.Text)
            report1.SetParameterValue("tardiness", payslip_tardiness.Text)
            report1.SetParameterValue("totalDeductions", payslip_totalDeductions.Text)
            report1.SetParameterValue("netPay", payslip_netPay.Text)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Printer_Frm.CrystalReportViewer1.ReportSource = report1
        Printer_Frm.ShowDialog()
    End Sub

I tried every codes I know to convert these data to string type but nothing works. Is there another ways to get my required output for these? Thanks ^_^



Solution 1:[1]

My problem is now solved. I use these codes Dim inDate As String = Format(dgr.Cells(0).Value, "MM-dd-yyyy") instead of these Dim inDate As String = CStr(dgr.Cells(0).Value.ToString("MM-dd-yyyy")). Thanks guys ^_^

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cookieMonster