Getting error "Dataset ds is empty or does not contain data."
Private Sub PrintEnvelop2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ds As New Client_Comp_DataSet()
' Ensure connections are open
If con1.State <> ConnectionState.Open Then
con1.Open()
End If
' Create data adapters for both tables
Dim da1 As New SqlDataAdapter("SELECT CompName, Add1, Phone FROM Client_Company WHERE CompID = @dts2", con1)
da1.SelectCommand.Parameters.AddWithValue("@dts2", dts2)
Dim da2 As New SqlDataAdapter("SELECT Comp_Name, CompAdd, CompLogo, Comp_Name_Marathi FROM Company WHERE Comp_ID = @dts3", con1)
da2.SelectCommand.Parameters.AddWithValue("@dts3", dts3)
' Create DataTables to hold the data
Dim dt1 As New DataTable("Client_Comp_DataTable")
Dim dt2 As New DataTable("Comp_DataTable1")
' Fill the DataTables with data from the tables
da1.Fill(dt1)
da2.Fill(dt2)
' Close connections
con1.Close()
' Debugging: Check if dt1 and dt2 have data
If dt1.Rows.Count = 0 Then
MessageBox.Show("No data in dt1")
Return
End If
If dt2.Rows.Count = 0 Then
MessageBox.Show("No data in dt2")
Return
End If
' Debugging: Display data from dt1 and dt2
MessageBox.Show("dt1 has " & dt1.Rows.Count & " rows.")
MessageBox.Show("dt2 has " & dt2.Rows.Count & " rows.")
' Add the data from dt2 to dt1
dt1.Merge(dt2)
' Debugging: Check if dt1 has data after merging
MessageBox.Show("dt1 after merge has " & dt1.Rows.Count & " rows.")
' Add the combined DataTable to the dataset
ds.Tables.Add(dt1)
' Debugging: Check DataTable names in the dataset
For Each table As DataTable In ds.Tables
MessageBox.Show("DataTable name: " & table.TableName)
Next
' Debugging: Check DataTable schema
For Each column As DataColumn In dt1.Columns
MessageBox.Show("Column name: " & column.ColumnName & ", Data type: " & column.DataType.ToString())
Next
DataGridView1.DataSource = dt1
' Debugging: Check if dataset contains data
If ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
' Create a new instance of the report
Dim report As New Envelop3()
' Set the dataset as the data source for the report
report.SetDataSource(ds)
' Assign the report to the CrystalReportViewer
crvEnvelop2.ReportSource = report
' Refresh the report
crvEnvelop2.RefreshReport()
Else
MessageBox.Show("Dataset ds is empty or does not contain data.")
End If
End If
Catch ex As Exception
MessageBox.Show("An error occurred: " & ex.Message)
Finally
' Close connection if open
If con1.State = ConnectionState.Open Then
con1.Close()
End If
End Try
End Sub