Datatable has more than 45000 number of rows. i want to insert this data to ms sql server table using stored procedure. what is the best way to do this without lagging. using xmls or ?
Loading
Datatable has more than 45000 number of rows. i want to insert this data to ms sql server table using stored procedure. what is the best way to do this without lagging. using xmls or ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Sep 19, 2023, 10:59 AM
SQL Server provides a feature called SQL Bulk Copy, which is specifically designed for efficiently inserting large amounts of data into a table. It's much faster than individual INSERT statements. You can try this.
Manjit VaghadiyaPosted Sep 19, 2023, 10:25 AM
Hi,
Lahiru Kalutotage
You can insert/update data using the data table to sql server using the storeprocedure by using this way.
Store Procedure
from C# backend code you need to pass
Ajay KumarPosted Sep 19, 2023, 10:15 AM
Inserting a large number of rows into a SQL Server table can be challenging, as you'll want to ensure the process is efficient and doesn't cause performance issues. There are several methods you can consider, including using XML, BULK INSERT, or SqlBulkCopy. The best approach depends on your specific requirements and constraints. Here's an overview of these methods:
XML: You can serialize your DataTable into XML and pass it to a stored procedure as a parameter. The stored procedure can then parse the XML and insert the data into the table. This can work well for smaller datasets, but it may not be the most efficient method for very large datasets, as XML parsing can be resource-intensive.
BULK INSERT: SQL Server provides a
BULK INSERTstatement that allows you to efficiently load data from a flat file into a table. You can write your DataTable to a CSV or other flat file format and then useBULK INSERTto load it into your target table. This method can be highly efficient for large datasets.3. SqlBulkCopy: If you're working with .NET (C# or VB.NET), you can use the
SqlBulkCopyclass to efficiently insert a large number of rows into a SQL Server table. This method is highly efficient and suitable for very large datasets. It leverages bulk insert operations and is often the preferred method for high-performance data insertion.