473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ADO.NET Inserts

I'm finding it hard to believe that this is "as good as it gets" when inserting rows into a database. The code below inserts 40,000 rows in about 1.7 seconds. I have read other posts that folks are getting much quicker times. Is this as good as it gets? Thank you for any insight.

Expand|Select|Wrap|Line Numbers
  1. Private Sub InsertTest(ByVal Connection As SqlConnection)
  2.             Using DBTrans As SqlTransaction = Connection.BeginTransaction
  3.                 Using cmdSQL As SqlCommand = Connection.CreateCommand()
  4.                     cmdSQL.Transaction = DBTrans
  5.                     cmdSQL.CommandText = "INSERT INTO TestCase(MyValue) VALUES(@Field1); INSERT INTO TestCase(MyValue) VALUES(@Field2); INSERT INTO TestCase(MyValue) VALUES(@Field3); INSERT INTO TestCase(MyValue) VALUES(@Field4)"
  6.                     Dim Field1 As SqlParameter = cmdSQL.CreateParameter()
  7.                     Field1.ParameterName = "@Field1"
  8.  
  9.                     Dim Field2 As SqlParameter = cmdSQL.CreateParameter()
  10.                     Field2.ParameterName = "@Field2"
  11.  
  12.                     Dim Field3 As SqlParameter = cmdSQL.CreateParameter()
  13.                     Field3.ParameterName = "@Field3"
  14.  
  15.                     Dim Field4 As SqlParameter = cmdSQL.CreateParameter()
  16.                     Field4.ParameterName = "@Field4"
  17.  
  18.                     cmdSQL.Parameters.Add(Field1)
  19.                     cmdSQL.Parameters.Add(Field2)
  20.                     cmdSQL.Parameters.Add(Field3)
  21.                     cmdSQL.Parameters.Add(Field4)
  22.  
  23.                     For i As Integer = 1 To 10000
  24.                         Field1.Value = i
  25.                         Field2.Value = i + 1
  26.                         Field3.Value = i + 2
  27.                         Field4.Value = i + 3
  28.                         cmdSQL.ExecuteNonQuery()
  29.                     Next
  30.                 End Using
  31.                 DBTrans.Commit()
  32.             End Using
  33.         End Sub
  34.  
Apr 16 '09 #1
6 1601
debasisdas
8,127 Expert 4TB
A lot will depend on if the server is local or a remote server and the network traffic.
Apr 17 '09 #2
CyberSoftHari
487 Expert 256MB
Try to run loops in stored procedure (No Inputs getting from user)
Apr 17 '09 #3
Frinavale
9,735 Expert Mod 8TB
Have you considered using a DataAdapter?

DataAdpaters are used to fill DataSets. DataSets are loaded into memory with the data from the database by a DataAdapter. They contain a bunch of tables that exist in memory. Once you are finished editing these tables you can call the DataAdapter's Update method to update the database.

-Frinny
Apr 17 '09 #4
@Frinavale
Yes I have tried the DataAdapter's Update method. The results are slower using Update. Thank you though.
Apr 20 '09 #5
@debasisdas
I'm running these tests on a local server.
Apr 20 '09 #6
@CyberSoftHari
I have not tried stored procedures yet. Will using SP make that much of a difference?
Apr 20 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: kerri | last post by:
Hi, I need to do a mysqldump of specific inserts, updates & deletes. I read in the docs that I can use -w or --where. Can I do a join? Could someone provide an example? Is there another...
3
by: Viswanatha Thalakola | last post by:
Hello, Can someone point me to getting the total number of inserts and updates on a table over a period of time? I just want to measure the insert and update activity on the tables. Thanks....
3
by: Chris Ochs | last post by:
First of all, we are still running sapdb at the moment but are in the process of moving to postgresql, so it seemed a good idea to post this type of question here. In our environment we have...
7
by: Steven D.Arnold | last post by:
How good is Postgres' performance for massive simultaneous insertions into the same heavily-indexed table? Are there any studies or benchmarks I can look at for that? I understand Postgres uses...
3
by: deathyam | last post by:
Hi, I have an Excel 97 app in which I'm using SQL INSERTs to insert data into an Access 97 database table. The table structure is as follows: VersionID (PK) (Long) MetricID (PK) (Long)...
2
by: simonZ | last post by:
I create a transaction: sqlTran=sqlConn.BeginTransaction(IsolationLevel.Serializable); Then, I insert some data into report table with sqlCommand object: oCmd = new...
0
by: poe | last post by:
Hello, I have a large database table running on SQL Server 8.0. It currently has nearly 98 million records on it's ways to 125 million. I am doing inserts as quickly as the server can handle it,...
18
by: Charles Law | last post by:
I have a sproc that returns data from a table using a simple SELECT. There are quite a few rows returned, e.g. ~150,000. In my first application, I use a reader on the sproc and iterate through...
3
by: Amber | last post by:
We are using 8.2.9 Windows 64 edtion, in one of our projects we need to recreate a few lager tables which have many millions of rows each, we have used concurrent Java threads to read from data...
4
by: wizardry | last post by:
hello - i've created a form that has multiple inserts. it inserts the data fine if i manually parse the data to it but when i use the form to test the inserts it errors out. it errors out at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.