Click here to Skip to main content
Click here to Skip to main content

DataSet to String to DataSet

, 10 Nov 2011
Rate this:
Please Sign up or sign in to vote.
Converting DataSet to String to DataSet.

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):

'my table name
Dim myRPT As String = "RPT_" & RM.rptID
'my report name (I'm using Crystal)
Dim xRpt As String = RM.rptID & "_rpt.rpt"
Dim oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
oRpt.Load(xRpt)
 
'RM.procName is my Stored Proc Name
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()
 
'And here's my DataSet name into String
'Why I did this, I need to recreate this for my 52 Crystal Reports
'and instead doing such long coding.. I did this.

Dim Rptds As String = RM.rptID & "_ds.xsd"
Dim da As SqlDataAdapter = New SqlDataAdapter(comm)
Dim myDS As New DataSet(Rptds) '< ----- String to DataSet

da.Fill(myDS, myRPT)
oRpt.SetDataSource(myDS)
ReportMain.CrystalReportViewer2.ReportSource = oRpt
 
Call CrystalReportProperties_()
conn.Close()

I hope this helps. Any comments/suggestions are welcome!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Alan Tuscano

Philippines Philippines
No Biography provided

Comments and Discussions

 
GeneralApart from giving your Dataset a name I'm not sure what tip ... PinmemberSimon_Whale11-Nov-11 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 10 Nov 2011
Article Copyright 2011 by Alan Tuscano
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid