Dear All,
i had query out the data from db in text box using reader, May i know how to pass the value in other Class ?
For example, based on below code, after i query the data from DB, then i click other button, it will save the data in PDF file.
private void button2_Click(object sender, EventArgs e) { string MyConString = ConfigurationManager.ConnectionStrings["OUMConnectionString"].ConnectionString; using (SqlConnection connection = new SqlConnection(MyConString)) { connection.Open(); using (SqlCommand cmd = new SqlCommand("select * from StudentDetails where StudentID = @studentID;", connection)) { cmd.Parameters.AddWithValue("@studentID", studentID); using (SqlDataReader reader = cmd.ExecuteReader()) { StringBuilder sb = new StringBuilder(); while (reader.Read()) { textBox1.Text = studentID; textBox2.Text = reader.GetString(2); textBox3.Text = reader.GetString(3); textBox4.Text = reader.GetString(4); textBox5.Text = reader.GetString(5); textBox6.Text = reader.GetString(6); dateTimePicker1.Text = reader.GetString(7); textBox7.Text = reader.GetString(8); textBox8.Text = reader.GetString(9); comboBox1.Text = reader.GetString(10); Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(Application.StartupPath + "/TrainedFaces/" + reader.GetString(11) + ".bmp"); Application.Idle -= new EventHandler(ProcessFrame); pictureBox1.Image = img1; } } } } }
private void button4_Click(object sender, EventArgs e) { Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f); iTextSharp.text.Font NormalFont = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK); PdfWriter wri = PdfWriter.GetInstance(document, new FileStream("Student.pdf", FileMode.Create)); document.Open(); // Pass the Reader Value here document.Close(); }