void showDetailBack() { try { // int check1 = 0; String connection = @"Data Source=DESKTOP-MV18312;Initial Catalog=SIU_database;Integrated Security=True"; String queryString1 = "SELECT StudentID,FirstName,LastName,Batch,Stream,DateOfBirth,Sex,SchoolName,HomeAddress,TelephoneNumber,EmailAddress,AdmissionDate FROM StudentMainDetail where StudentID ='" + valueS1 + "'"; using (SqlConnection connectionObj1 = new SqlConnection( connection)) { SqlCommand command1 = new SqlCommand( queryString1, connectionObj1); connectionObj1.Open(); SqlDataReader reader = command1.ExecuteReader(); try { Console.WriteLine(reader); while (reader.Read()) { String t1 = (String)reader[0]; String t2 = (String)reader[1]; String t3 = (String)reader[2]; String t4 = (String)reader[3]; String t5 = (String)reader[4]; String t6 = (String)reader[5]; String t7 = (String)reader[6]; String t8 = (String)reader[7]; String t9 = (String)reader[8]; String t10 = (String)reader[9]; String t11 = (String)reader[10]; String t12 = (String)reader[11]; DetailOfAStudent detailOfStudent = new DetailOfAStudent(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12); detailOfStudent.Show(); this.Close(); } } finally { // Always call Close when done reading. reader.Close(); } } //----------------------------------------------------------------------------- //connectionObj.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void dataGridViewByName_CellClick(object sender, DataGridViewCellEventArgs e) { dataGridViewByName.SelectionMode = DataGridViewSelectionMode.FullRowSelect; int index1 = e.RowIndex; DataGridViewRow selectedRow = dataGridViewByName.Rows[index1]; String t1 = selectedRow.Cells[0].Value.ToString(); String t2 = selectedRow.Cells[1].Value.ToString(); String t3 = selectedRow.Cells[2].Value.ToString(); String t4 = selectedRow.Cells[3].Value.ToString(); String t5 = selectedRow.Cells[4].Value.ToString(); String t6 = selectedRow.Cells[5].Value.ToString(); String t7 = selectedRow.Cells[6].Value.ToString(); String t8 = selectedRow.Cells[7].Value.ToString(); String t9 = selectedRow.Cells[8].Value.ToString(); String t10 = selectedRow.Cells[9].Value.ToString(); String t11 = selectedRow.Cells[10].Value.ToString(); String t12 = selectedRow.Cells[11].Value.ToString(); DetailOfAStudent detailOfStudent = new DetailOfAStudent(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12); detailOfStudent.Show(); this.Hide(); }