Code:
TypeScript
private void dgvUQ_CellValueChanged(object sender, DataGridViewCellEventArgs e) { dc.GainConnection(" ", dgvUQ, "v_stafftrainingDetails"); }Code:
C#
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 HobbsRank #107 · 20.5K reputationPosted Apr 2, 2012, 11:47 AM EDT
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.
Luke Baker20 reputationPosted Apr 2, 2012, 12:14 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 2, 2012, 2:07 PM EDT
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 Baker20 reputationPosted Apr 2, 2012, 2:15 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 2, 2012, 2:42 PM EDT
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.