Strange Behavior of Date format in Report Viewer When i convert it to a string

  • Thread starter Thread starter Amr_Aly
  • Start date Start date
A

Amr_Aly

Guest
I am using this code

Using con As New SqlConnection(cs)
con.Open()
Using cmd As New SqlCommand(
"select ID,
MDate,
EXName,
EXData,
TelNo,
Amount,
EmpName
from ExpensesBill2")
cmd.CommandType = CommandType.Text
cmd.Connection = con
Using ds As New DataSet, da As New SqlDataAdapter()
da.SelectCommand = cmd

'Convert Datagridview to Datatable
Dim gdt As New DataTable
gdt.Columns.Add("ID")
gdt.Columns.Add("MDate")
gdt.Columns.Add("EXName")
gdt.Columns.Add("EXData")
gdt.Columns.Add("TelNo")
gdt.Columns.Add("Amount")
gdt.Columns.Add("EmpName")

For i = 0 To DataGridView1.Rows.Count - 1
gdt.Rows.Add(DataGridView1.Rows(i).Cells(0).Value,
DataGridView1.Rows(i).Cells(1).Value,
DataGridView1.Rows(i).Cells(2).Value,
DataGridView1.Rows(i).Cells(3).Value,
DataGridView1.Rows(i).Cells(4).Value,
DataGridView1.Rows(i).Cells(5).Value,
DataGridView1.Rows(i).Cells(6).Value)
Next

ReportExpForm34.ReportViewer1.LocalReport.DataSources.Clear()
ReportExpForm34.ReportViewer1.LocalReport.ReportPath = Reportpath + "Report9.rdlc"

Dim rds = New ReportDataSource("DataSet1", gdt)
ReportExpForm34.ReportViewer1.LocalReport.DataSources.Add(rds)

If ReportExpForm34.ShowDialog() = DialogResult.OK Then
Else
End If
ReportExpForm34.Dispose()
End Using
End Using
End Using

and i am using this Expression {=Format(CDate(Fields!MDate.Value), "dd/MM/yyyy")} and this one also {=FormatDateTime(Fields!MDate.Value, FormatDate("dd/MM/yyyy"))} it works nice and gave me what i want ,

But there is a big problem occurs when printing this report some of rows appear normal date like this (29/06/2020) and the above rows appear like (#Error) but when i remove the expression and return to the original format like this(29/06/2020 12:00:00)it prints the report normally ..... My question is How can i get rid of the (#Error) to get all rows like this (29/06/2020)


Regards From Egypt

Continue reading...
 
Back
Top