TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Steps to Pass Parameters to Crystal Reports in C#
Pintoo Yadav
Apr 20
2015
Code
4.3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
First Step
//getting and set dataset to report
string
sql =
"select * from bill_mst"
;
DataRetriever dr =
new
DataRetriever();
dr.getValueFromCustomer(sql);
DataTable dtSum = dr.getDataTable();
dsMyReprt k =
new
dsMyReprt();
k.Tables.Remove(
"billmst"
);
dtSum.TableName =
"billmst"
;
k.Tables.Add(dtSum);
CrystalReport1 myDataReport =
new
CrystalReport1();
//pass parameter
DataSet ds =
new
DataSet();
// con = new OleDbConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
OleDbConnection con = Gbl_Cls.conection();
// new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ClientMgmtDb1.accdb;");
if
(con.State == ConnectionState.Closed) con.Open();
OleDbDataAdapter da =
new
OleDbDataAdapter();
OleDbDataAdapter da1 =
new
OleDbDataAdapter();
// if(txtbillno.Text.Trim().Length==0)
if
(txtbillno.Text !=
""
)
{
// MessageBox.Show("Enter Bill number");
da =
new
OleDbDataAdapter(
"select ID,NAME,BILL_Number,Date,Address,PO_Number,PO_Date,Narat,Quantity,Rate,Total_price,Vat,Serves_tax,vatAmt,StaxAmt,IncludeTax_AMT,amount,Total_vatAmt,Total_StaxAmt,STax_Amount,VTax_Amount FROM Bill_Mst1 where ID="
+ txtbillno.Text.Trim() +
""
, con);
da1 =
new
OleDbDataAdapter(
"select ID,[BILL_Number],[Narat],[Quantity],[Rate],[Amount],[vatAmt],[StaxAmt] from product_mst where ID="
+ txtbillno.Text.Trim() +
""
, con);
}
da.Fill(ds,
"Bill_Mst"
);
da1.Fill(ds,
"Product"
);
if
(ds.Tables.Count > 0)
{
Bill2 cr =
new
Bill2();
CrystalReport1 cr1 =
new
CrystalReport1();
cr.SetDataSource(ds);
cr1.SetDataSource(ds.Tables[
"Product"
]);
this
.crystalReportViewer1.ReportSource = cr;
this
.crystalReportViewer1.Show();
crystalReportViewer1.Refresh();
}
con.Close();
}
catch
(OleDbException s)
{
MessageBox.Show(
"Server Problem..."
);
}
Second Step
ParameterFields paramFields =
new
ParameterFields();
// ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
ParameterField paramField =
new
ParameterField();
ParameterDiscreteValue paramDiscreteValue =
new
ParameterDiscreteValue();
paramField.Name =
"@DTotal"
;
paramDiscreteValue.Value = tot;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField =
new
ParameterField();
paramDiscreteValue =
new
ParameterDiscreteValue();
paramField.Name =
"@name"
;
paramDiscreteValue.Value = name;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
crystalReportViewer1.ParameterFieldInfo = paramFields;
myDataReport.SetDataSource(k);
crystalReportViewer1.ReportSource = myDataReport;
Crystal Reports in C#
Pass Parameters to Crystal Reports