简体   繁体   中英

insert file data in a SQL table

How can I insert data in a file full of data all together in a table using SQL command?

I am already doing it using foreach but what if I do not want to insert row by row but all together?

If this is SQL Server, then your best bet there would be SqlBulkCopy (with or without a transaction, as you require); for the source you can either load all the data from the file into a DataTable , or in some cases you can create an unbuffered IDataReader that streams the data through the file as needed. The IDataReader approach is more efficient and faster, but more complex unless a convenient IDataReader implementation already exists for your input data (for example, CsvReader for delimited data). The DataTable approach requires all the data to be buffered in-memory first and is slower, but often more convenient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM