将相同的数据插入数据库两次 [英] same data inserted 2 times in database

查看:129
本文介绍了将相同的数据插入数据库两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我,我有学生表(名字,姓氏,父亲,电话,地址).我将数据插入数据库两次,将要插入的数据.例如:

插入到studentmaster(firstname,lastname,fathername,phone,address)的值中(``aaaa'',``bbbb,''cccc'',1111,``delhi'');

pls help me, i have table studentmaster(firstname,lastname,fathername,phone,address). i am inserting data into database 2 times the data will be inserted. forexample:

insert into studentmaster(firstname,lastname,fathername,phone,address) values(''aaaa'',''bbbb,''cccc'',1111,''delhi'');

推荐答案

在数据库中插入一行时,将插入一行.在任何情况下,数据库都不会自动复制该行.重复的可能原因至少包括:

  • 您两次执行该语句:例如,尝试查找是否在代码中两次错误地调用了ExecuteNonQuery.
  • insert语句在您的SQL字符串中包含两次.使用调试器,查看insert语句是否两次被错误地放置到SQL字符串中.
  • 您的代码中的方法被两次调用.这应该很容易确定.在方法上放一个断点,看看何时被击中
  • 您有一个触发重复的触发器.使用SSMS调查表的触发器
  • 一个过程执行插入操作:查看是否有一个过程插入另一行以及是否从应用程序(或触发器)中调用了该行
When you insert a row to the database, a single row is inserted. The database doesn''t duplicate the row automatically in any case. Possible reasons for the duplication include at least:

  • you execute the statement twice: Try to find if you for example have the call to ExecuteNonQuery mistakenly twice in your code
  • the insert statement is included twice in your SQL string. Using debugger, see if the insert statement is mistakenly put to the SQL string twice.
  • the method in your code is called twice. This should be easy to pinpoint. Put a breakpoint on the method and see when it''s hit
  • you have a trigger that''s causing the duplication. Investigate the triggers of the table using SSMS
  • a procedure does the insertion: see if you have a procedure that inserts the other row and if it''s called from your application (or from a trigger)


这篇关于将相同的数据插入数据库两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆