private void button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=.;Initial Catalog=VoterData;User ID=sa;Password=mdc@123";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("select Voter_ID,Name,[House No],Age,Gender,Assem_constituency,Parliment_constituency,[Polling Station] from Malkajgiri", con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
CrystalDecisions.CrystalReports.Engine.ReportDocument doc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\CrystalReport1.rpt";
path = path.Replace("file:\\", "");
path = path.Replace("bin\\Debug\\", "");
CrystalReport1 cr = new CrystalReport1();
doc.Load(path);
doc.SetDataSource(dt.DefaultView);
if (dt.Rows.Count == 0)
{
MessageBox.Show("No data Found", "CrystalReportWithOracle");
return;
}
else
{
crystalReportViewer1.ReportSource = doc;
crystalReportViewer1.Visible = true;
crystalReportViewer1.Refresh();
con.Close();
}
}