steve_rm
Oct 30th, 2006, 07:52 AM
Hello,
I am not going to waste too much of your time. Thanks for your help with my last problem. However, I have another problem. I want to display in my report data from 2 different tables. I have created the typed dataset and join the tables.
In CR I have added the dataset to my report designer.
I have stored procedure that selects from 2 tables based on a incidentID number. However, my report only displays from the incidents table.
Example of my tables.
[incident] IncidentID (PK), Company, phoneno, contact, etc
[IncidentTask] taskID (PK), IncidentID (FK), details
My query
ALTER PROCEDURE [dbo].[printJobSheet]
@incidentID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT incident.incidentID, incident.company, incident.subject, incident.contact, incident.phoneNo, incident.email, incidentTask.TaskID, incidentTask.Details
FROM incident INNER JOIN incidentTask on incident.incidentID = incidentTask.incidentID
WHERE incident.incidentID = @incidentID
END
The repeating field are in the incidentTask table (TaskID, Details) These will be in the detailed section of the report. The other fields from the incident table will be in the header.
The way I am fill my dataset which is a typed dataset is as follows:
Try
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "printJobSheet"
Dim pIncidentID As New SqlParameter()
pIncidentID.ParameterName = "@IncidentID"
pIncidentID.DbType = DbType.Int16
pIncidentID.Direction = ParameterDirection.Input
pIncidentID.Value = IDNumber
cmd.Parameters.Add(pIncidentID)
DS_JobSheet2 = New DataSet
cnn.Open()
cmd.Connection = cnn
da.SelectCommand = cmd
da.Fill(DS_JobSheet2)
dt = DS_JobSheet2.Tables(0)
report.Load(Application.StartupPath & "/rptJobSheet2.rpt")
report.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = report
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
If I do a SELECT * FROM Incident
or
SELECT * FROM IncidentTask
It works, but not when I join the tables together. I have created the xsd typed datasets and have the in my report.
A example working program would be wonderful, but I don't want to take too much of your time.
Thanks in advance,
Steve
I am not going to waste too much of your time. Thanks for your help with my last problem. However, I have another problem. I want to display in my report data from 2 different tables. I have created the typed dataset and join the tables.
In CR I have added the dataset to my report designer.
I have stored procedure that selects from 2 tables based on a incidentID number. However, my report only displays from the incidents table.
Example of my tables.
[incident] IncidentID (PK), Company, phoneno, contact, etc
[IncidentTask] taskID (PK), IncidentID (FK), details
My query
ALTER PROCEDURE [dbo].[printJobSheet]
@incidentID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT incident.incidentID, incident.company, incident.subject, incident.contact, incident.phoneNo, incident.email, incidentTask.TaskID, incidentTask.Details
FROM incident INNER JOIN incidentTask on incident.incidentID = incidentTask.incidentID
WHERE incident.incidentID = @incidentID
END
The repeating field are in the incidentTask table (TaskID, Details) These will be in the detailed section of the report. The other fields from the incident table will be in the header.
The way I am fill my dataset which is a typed dataset is as follows:
Try
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "printJobSheet"
Dim pIncidentID As New SqlParameter()
pIncidentID.ParameterName = "@IncidentID"
pIncidentID.DbType = DbType.Int16
pIncidentID.Direction = ParameterDirection.Input
pIncidentID.Value = IDNumber
cmd.Parameters.Add(pIncidentID)
DS_JobSheet2 = New DataSet
cnn.Open()
cmd.Connection = cnn
da.SelectCommand = cmd
da.Fill(DS_JobSheet2)
dt = DS_JobSheet2.Tables(0)
report.Load(Application.StartupPath & "/rptJobSheet2.rpt")
report.SetDataSource(dt)
Me.CrystalReportViewer1.ReportSource = report
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
If I do a SELECT * FROM Incident
or
SELECT * FROM IncidentTask
It works, but not when I join the tables together. I have created the xsd typed datasets and have the in my report.
A example working program would be wonderful, but I don't want to take too much of your time.
Thanks in advance,
Steve