private void button1_Click(object sender, EventArgs e) { bool details = false; opd opd = new opd(); dbconnect db = new dbconnect(); opd.getPatientDetailsHistory(textBox1.Text, db); if (opd.dr.Read()) { id = textBox1.Text; name = opd.dr[0].ToString(); gender = opd.dr[1].ToString(); familyHead = opd.dr[2].ToString(); details = true; } else { MessageBox.Show("Invalid Patient ID!!"); db.dbclose(); } db.reader_close(); if (details) { opdCount = 0; medicineCount = 0; opd.patientAge(id); age = opd.age.ToString(); opd.getPatientOPDHistory(textBox1.Text, db); while (opd.dr.Read()) { medicine_id = opd.dr[2].ToString().Split(','); medicineCount += medicine_id.Length; opdCount += 1; } db.dbclose(); printPreviewDialog1.ShowDialog(); } }