private void btnSave_Click(object sender, EventArgs e) { string StrQuery; try { using (SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"])) { conn.ConnectionString = "Data Source=user-PC;Initial Catalog=MUCGPROJECT;User ID=sa;Password=mike"; using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; //conn.Open(); for (int i = 0; i < dgvDistrict.Rows.Count; i++) { StrQuery = @"INSERT INTO DistrictnT VALUES ('" + this.txtDistrict.Text + "', '" + dgvDistrict.Rows[i].Cells["clmTowns"].Value + "');"; comm.CommandText = StrQuery; conn.Open(); comm.ExecuteNonQuery(); conn.Close(); } cleardgv(); MessageBox.Show("Record is successfully Added"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)