private void btngeneratereceipt_Click(object sender, EventArgs e) { try { using (SqlConnection con1 = new SqlConnection(cs)) { con1.Open(); SqlCommand cmd = new SqlCommand("Select * from DonationDetails Where ReceiptNo = " + txtRno.Text + "", con1); SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); CrystalReport cr = new CrystalReport(); CrystalReport1 c = new CrystalReport1(); c.SetDataSource(dt); cr.crystalReportViewer1.ReportSource = c; cr.crystalReportViewer1.Refresh(); cr.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnreceipt_Click(object sender, EventArgs e) { if (validate()) { string cs = ConfigurationManager.ConnectionStrings["dbc"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { try { con.Open(); string query = "Insert into DonationDetails values(@ReceiptNo,@Name,@Date,@Amount,@DonatedIN,@PANCardNo,@Address,@Email,@Description)"; SqlCommand cmd = new SqlCommand(query, con); cmd.Parameters.Add("@ReceiptNo", SqlDbType.Int, 0, "ReceiptNo").Value = int.Parse(txtreceiptno.Text); cmd.Parameters.Add("@Name", SqlDbType.VarChar, 250, "Name").Value = txtname.Text; cmd.Parameters.Add("@Date", SqlDbType.Date, 0, "ReceiptDate").Value = dateTimePicker1.Value; cmd.Parameters.Add("@Amount", SqlDbType.Money, 0, "Amount").Value = double.Parse(txtamount.Text); cmd.Parameters.Add("@DonatedIN", SqlDbType.VarChar, 100, "DonationIN").Value = comboBox1.SelectedItem.ToString(); cmd.Parameters.Add("@PANCardNo", SqlDbType.NVarChar, 100, "PANCardNo").Value = txtCardNo.Text; cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 500, "Address").Value = txtaddress.Text; cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 100, "emailID").Value = txtemail.Text; cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 500, "Descripetion").Value = txtdiscreption.Text; cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Donor Details has been stored"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con1 = new SqlConnection(cs)) { try { con1.Open(); SqlCommand cmd = new SqlCommand("Select * from DonationDetails Where ReceiptNo = " + txtreceiptno.Text + "", con1); SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); CrystalReport cr = new CrystalReport(); CrystalReport1 c = new CrystalReport1(); c.SetDataSource(dt); cr.crystalReportViewer1.ReportSource = c; cr.crystalReportViewer1.Refresh(); cr.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }