hello guys.. beginner po aq sa paggawa ng Crystal Report... tumingin na po aq sa youtube kaso ayaw naman gumana sakin..VB.net 2010 at SQL po gamit q database.. gusto q po sana gumawa ng Report using dataset.. any help po salamat..
Instructions:
-Open your project
-Right click on your
Solution's Name and click
Add ->
New Item then select dataset give it a name of your choice then click
Add
-On the Server Explorer right click Data Connections and then click Add Connection.
-Enter your server name and other credentials and select the
Database.
-After that drag a table(yung table na panggagalingan ng report mo) to the
DataSet Tab that you created.
-Now right click on the project in
Solution Explorer and select
Add New Item. Select
Crystal Report from the list and name it as you want
-The
Crystal Report Gallery will open. Select
Blank Report and click OK.
-Now in the field explorer window right click on Database Fields and click
Database Expert.
-Click the plus sign of Project Data, then ADO.NET
DataSets. Select the table that you have added in your
DataSet . Click the add (>) button to add the table to our report and click OK.
-You will get all the fields of the table that you have selected from Database Fields in Field Explorer. Drag and drop the required fields of you report(i-design mo na yung report mo) then save it.
-Finally drag CrystalReportViewer control from the Reporting section of the Toolbox into a Form dedicated for viewing reports. Or add new
Windows Form then drag it there.
-Now go to the code behind page and write the following code in the Form's Load event:
private void Form1_Activated(object sender, EventArgs e)
{
Application.DoEvents();
try
{
SqlConnection connection = new SqlConnection("Server=your_server;uid=sa;pwd=your_password;Database=your_database_name");
SqlCommand command = new SqlCommand("Select * From your_table", connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataset = new DataSet();
adapter.Fill(dataset, "any_name");
ReportDocument your_prefered_name = new ReportDocument();
your_prefered_name.Load(@"your_report's_fullpath_here_Or_use_.NetObject_than_will_map_your_report");
your_prefered_name.SetDataSource(dataset.Tables["any_name"]);
crystalReportViewer1.ReportSource = your_prefered_name ;
crystalReportViewer1.RefreshReport();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace, "Error!");
}
}
-Run the Program and view the report.
-Get debugging whenever things wont work.
-If there are other questions or error just post it back here sir.
-Happy CODING!
*Advise ko lang sir, pagaralan mo ang gumamit ng stored procedures para lahat ng queries mo(kahit hindi sa reports) ay sa SQL lahat nakalagay. sa case ng pag-gawa ng report, mahabang proseso ang report generation using
DataSet, pag Stored Proc. yan, lesser procedure, more secure and best practice.