Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.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
Sql server 如何在SQLServer中通过存储过程插入数据表_Sql Server - Fatal编程技术网

Sql server 如何在SQLServer中通过存储过程插入数据表

Sql server 如何在SQLServer中通过存储过程插入数据表,sql-server,Sql Server,试图通过存储过程将数据表的多条记录插入SQL表。我需要将数据表的所有记录一起插入 我正在使用C#编程语言,我想通过ADO.net存储过程将许多记录一起发送到SQL server。我想知道数据表类型,如果对我有帮助的话就使用它。要高效地将许多行传递给存储过程,请使用。C#应用程序可以指定参数类型和数据表的值。为获得最佳性能,请确保DataTable列类型与服务器端表类型列类型匹配(包括字符串列的最大长度) 以下是从上述文档链接中摘录的示例: // Assumes connection is an

试图通过存储过程将数据表的多条记录插入SQL表。我需要将数据表的所有记录一起插入


我正在使用C#编程语言,我想通过ADO.net存储过程将许多记录一起发送到SQL server。我想知道数据表类型,如果对我有帮助的话就使用它。

要高效地将许多行传递给存储过程,请使用。C#应用程序可以指定参数类型和数据表的值。为获得最佳性能,请确保
DataTable
列类型与服务器端表类型列类型匹配(包括字符串列的最大长度)

以下是从上述文档链接中摘录的示例:

// Assumes connection is an open SqlConnection object.  
using (connection)  
{  
  // Create a DataTable with the modified rows.  
  DataTable addedCategories = CategoriesDataTable.GetChanges(DataRowState.Added);  

  // Configure the SqlCommand and SqlParameter.  
  SqlCommand insertCommand = new SqlCommand("usp_InsertCategories", connection);  
  insertCommand.CommandType = CommandType.StoredProcedure;  
  SqlParameter tvpParam = insertCommand.Parameters.AddWithValue("@tvpNewCategories", addedCategories);  
  tvpParam.SqlDbType = SqlDbType.Structured;  

  // Execute the command.  
  insertCommand.ExecuteNonQuery();  
}
下面是创建表类型和过程的T-SQL代码段

CREATE TYPE dbo.CategoryTableType AS TABLE  
    ( CategoryID int, CategoryName nvarchar(50) );
GO

CREATE PROC dbo.usp_InsertCategories
AS
@tvpNewCategories dbo.CategoryTableType READONLY
INSERT INTO dbo.Categories (CategoryID, CategoryName)  
    SELECT nc.CategoryID, nc.CategoryName FROM @tvpNewCategories AS nc;
GO
即使是简单的插入,TVP性能也可以提供(每秒数千次)存储过程接口的优势。

可能的