It took me three days searching the Net on how to make my DataSet
(s) String
type. I also asked for help but in some ways, could not make the code run. I then tried this simple yet very handy trick. If you have more than 10 reports and each one has its own DataSet
, you would want to avoid doing long Select Cases, If statements
, right!
A simple trick I have found is this:
Var_Ds
is the string
representing the DataSet
name da
is the Adapter
myDs
will be my new DataSet
Dim Var_ds as String = DsVarName & ".xsd"
Dim da As SqlDataAdapter = New SqlDataAdapter(comm)
Dim myDS As New DataSet(Var_ds)
Below is a working code (part of my working program):
Dim myRPT As String = "RPT_" & RM.rptID
Dim xRpt As String = RM.rptID & "_rpt.rpt"
Dim oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
oRpt.Load(xRpt)
Dim comm As SqlCommand = New SqlCommand(RM.procName, conn)
comm.CommandTimeout = 0
comm.CommandType = CommandType.StoredProcedure
Dim objParam As SqlParameter
objParam = comm.Parameters.Add("@transdate", SqlDbType.NVarChar, 10)
objParam.Direction = ParameterDirection.Input
objParam.Value = txndate
Dim objParam1 As SqlParameter
objParam1 = comm.Parameters.Add("@currency_cd", SqlDbType.NVarChar, 3)
objParam1.Direction = ParameterDirection.Input
objParam1.Value = curr_cd
comm.ExecuteNonQuery()
Dim Rptds As String = RM.rptID & "_ds.xsd"
Dim da As SqlDataAdapter = New SqlDataAdapter(comm)
Dim myDS As New DataSet(Rptds)
da.Fill(myDS, myRPT)
oRpt.SetDataSource(myDS)
ReportMain.CrystalReportViewer2.ReportSource = oRpt
Call CrystalReportProperties_()
conn.Close()
I hope this helps. Any comments/suggestions are welcome!