Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用存储过程将多行插入SQL Server 2005_C#_Sql Server 2005_Stored Procedures - Fatal编程技术网

C# 使用存储过程将多行插入SQL Server 2005

C# 使用存储过程将多行插入SQL Server 2005,c#,sql-server-2005,stored-procedures,C#,Sql Server 2005,Stored Procedures,我正在开发一个ASP.NET MVC/C应用程序 我有一个对象列表,比如说从CSV导入的list学生 我想使用存储过程和事务将它们插入SQLServer2005数据库。如果一行失败,它应该回滚 有什么建议吗 有两种方法 使用大容量插入命令进行大容量插入(从文件到数据库) 请检查这个 您可以生成XML,然后插入 请检查这个 谢谢, Anand您使用ADO还是实体 您可以使用代码中的事务。 麻烦 对于实体 try { entityTransaction = Context.Connect

我正在开发一个ASP.NET MVC/C应用程序

我有一个对象列表,比如说从CSV导入的
list
学生

我想使用存储过程和事务将它们插入SQLServer2005数据库。如果一行失败,它应该回滚


有什么建议吗

有两种方法

  • 使用大容量插入命令进行大容量插入(从文件到数据库)
  • 请检查这个

  • 您可以生成XML,然后插入
  • 请检查这个

    谢谢,
    Anand

    您使用ADO还是实体

    您可以使用代码中的事务。 麻烦

    对于实体

    try
    {
        entityTransaction = Context.Connection.BeginTransaction();
    
        //call insert in loop
    
        entityTransaction.Commit();
    }
    catch{
        entityTransaction.Rollback();
    }
    

    很好-所以继续写一些代码吧!若要将列表插入数据库,请选中此项
    try
    {
        entityTransaction = Context.Connection.BeginTransaction();
    
        //call insert in loop
    
        entityTransaction.Commit();
    }
    catch{
        entityTransaction.Rollback();
    }