“SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects”

后端 未结 8 1973
暗喜
暗喜 2021-01-04 07:23

I keep getting the exception

The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects

, while execut

8条回答
  •  [愿得一人]
    2021-01-04 07:49

    When you use Add method, you are trying to add a new parameter. What you want to do is to assign value. So change this:

    comm.Parameters.Add(dataGridView1.Rows[i].Cells[0].Value.ToString());
    

    to this:

    comm.Parameters["@author"].Value = dataGridView1.Rows[i].Cells[0].Value.ToString();
    

    Similarly for the other parameters.

提交回复
热议问题