private void dgvUQ_CellValueChanged(object sender, DataGridViewCellEventArgs e) { dc.GainConnection(" ", dgvUQ, "v_stafftrainingDetails"); }
public void GainConnection(string command, DataGridView dgv, string strTable) { SqlCommand com1 = new SqlCommand(); string conStr; conStr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\NTO.mdf;Integrated Security=True;User Instance=True"; SqlConnection connection = new SqlConnection(conStr); connection.Open(); com1.Connection = connection; com1.CommandType = CommandType.Text; com1.CommandText = command; DataSet ds = new DataSet(); SqlDataAdapter sqlAdp = new SqlDataAdapter(com1); sqlAdp.Fill(ds); sqlAdp.Update(ds); dgv.DataSource = ds; dgv.DataMember = strTable; connection.Close(); }