error 'there is already an open datareader associated with this command which must be closed first'

后端 未结 12 2298
情话喂你
情话喂你 2020-12-05 10:15

runtime error \'there is already an open datareader associated with this command which must be closed first\'

objCommand = new SqlCommand(\"SELECT field1, fi         


        
12条回答
  •  无人及你
    2020-12-05 11:13

    INSERT INTO tablename (field1, field2)
        SELECT 3, field1 FROM sourcetable
    

    A single SQL statement instead of one per insert. Not sure if this will work for your real-life problem, but for the example you provided, this is a much better query than doing them one at a time.

    On a side note, make sure your code uses parameterized queries instead of accepting strings as-is inside the SQL statement - your sample is open to SQL injection.

提交回复
热议问题