Code:
private void dgvUQ_CellValueChanged(object sender, DataGridViewCellEventArgs e) { dc.GainConnection(" ", dgvUQ, "v_stafftrainingDetails"); } Code:
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(); }
Sam HobbsPosted Apr 2, 2012, 6:42 PM
I suggest looking at some of the relevant articles in this web site. There are very many that can help you. I do not have enough information to know what else to suggest.
Luke BakerPosted Apr 2, 2012, 6:15 PM
Sam HobbsPosted Apr 2, 2012, 6:07 PM
It will help to know what source code line is getting the error.
Also, you are calling "sqlAdp.Fill(ds)" and sqlAdp is created with com1 and com1.CommandText = command. You do not show what is in the "command" parameter. What is in the "command" parameter?
Luke BakerPosted Apr 2, 2012, 4:14 PM
Sam HobbsPosted Apr 2, 2012, 3:47 PM
I don't see any SQL in your code. If the error is complaining about the SQL then the SQL is the most important data to show.