private void txtDistrict_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(Configuratiing = "Data Source=user-PC;Initial Catalog=MUCGPROJECT;User ID=sa;Password=mike"; string sqlQuery = null; sqlQuery = "select * from DistrictnT where District = '" + txtDistrict.Text + "'"; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sqlQuery; cmd.CommandType = System.Data.CommandType.Text; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); try { while (dr.Read()) { dgvDistrict.Rows[dgvDistrict.Rows.Count - 1].Cells["clmTowns"].Value = dr[2].ToString(); } } catch (Exception ex) { MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); } }
dgvDistrict.Rows[dgvDistrict.Rows.Count - 1]
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)