Design a Student Result Application in Windows form With Crystal Report
Also Export it to Pdf format.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
namespace PRG25_STUD_CRYSTAL_DEMO
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbStudent.mdf;Integrated Security=True;User Instance=True");
SqlCommand com;
SqlDataAdapter adp = new SqlDataAdapter();
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
private void btn_submit_Click(object sender, EventArgs e)
{
con.Open();
com = new SqlCommand("insert into tbl_student values ("+txt_rollno.Text+",'"+txt_name.Text+"','"+txt_sub1.Text+"','"+txt_sub2.Text+"','"+txt_sub3.Text+"')",con);
int x = com.ExecuteNonQuery();
con.Close();
if (x > 0)
{
ds.Tables[0].Rows.Clear();
CrystalAddData();
MessageBox.Show("Record Inserted");
}
}
private void Form1_Load(object sender, EventArgs e)
{
CrystalAddData();
}
public void CrystalAddData()
{
adp = new SqlDataAdapter("select * from tbl_student", con);
adp.Fill(ds);
ReportDocument rd = new ReportDocument();
rd.Load(@"~\CrystalReport1.rpt");
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
}
private void btn_search_Click(object sender, EventArgs e)
{
if (txt_search .Text == "")
{
MessageBox.Show("Enter Roll No");
}
else
{
ds.Tables[0].Rows.Clear();
adp = new SqlDataAdapter("select * from tbl_student where sno=" + txt_search .Text + "", con);
adp.Fill(ds);
ReportDocument rd = new ReportDocument();
rd.Load(@"~\CrystalReport1.rpt");
rd.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = rd;
}
}
private void btn_all_Click(object sender, EventArgs e)
{
ds.Tables[0].Rows.Clear();
CrystalAddData();
}
}
}
Comments
Leave a comment