将日期从DataGridView传输到Crystal Reports VB.NET



当我使用这些代码Dim inDate As String = CStr(dgr.Cells(0).Value.ToString("MM-dd-yyyy"))时。错误表示从字符串";MM-dd-yyyy";到类型integer无效。但是当我使用这些代码Dim inDate As String = CStr(dgr.Cells(0).Value。它显示GridView中的日期,但使用时间格式。我只想显示日期,而不是日期时间。将数据从网格视图传输到水晶报表。我使用了DataSet和DataTable。表中日期列的数据类型为字符串。这是我的完整代码。

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

我尝试了所有我知道的代码来将这些数据转换为字符串类型,但都不起作用。有没有其他方法可以获得这些所需的输出?谢谢^_^

我的问题现在解决了。我使用这些代码Dim inDate As String = Format(dgr.Cells(0).Value, "MM-dd-yyyy")而不是这些Dim inDate As String = CStr(dgr.Cells(0).Value.ToString("MM-dd-yyyy"))。谢谢各位^_^

相关内容

  • 没有找到相关文章

最新更新